user3425561
user3425561

Reputation: 79

LocationClient.getLastLocation() returns Null although connected

iam trying to receive my current location through the LocationClient but for some reason it returns null. I dont NOT want to use GPS therefore i have dummied out the fine location access permission in my Manifest.

Manifest:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!--  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> -->

MainActivity:

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
....
mLocationClient = new LocationClient(this, this, this); 
....
}

@Override
   protected void onStart() {
      super.onStart();
      // Connect the client.
      mLocationClient.connect();
}

@Override
   protected void onStop() {
      // Disconnect the client.
      mLocationClient.disconnect();
      super.onStop();
   }

@Override
   public void onConnected(Bundle dataBundle) {
      location = mLocationClient.getLastLocation();
       // do something with the current location
   }

For some reason it always returns null for location unless i open the settings on my phone and enable GPS. Once GPS is enabled i am able to get my location. It does get the location through the network though. i dont want to use GPS and i dont want it to be enabled. But if GPS is not enabled it doesnt get a location at all. any ideas what im doing wrong?

Upvotes: 2

Views: 2488

Answers (1)

Mehul Joisar
Mehul Joisar

Reputation: 15358

If you don't want to use GPS than it will get location from Network, enable it in your device as mentioned in below screenshot

Upvotes: 1

Related Questions