ssgao
ssgao

Reputation: 5501

getLastKnownLocation() always return the same location, even after device is moved

I set up my location manager by executing

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

Then I call have a update button on my app so that when it is pressed, the I will call executing the following line

Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER)

However, the location that I get is always the same one, even after I held the device and walk straight for 20 meters and then wait for 10 minutes!

May I ask if I missed anything?

Thanks!

Upvotes: 1

Views: 2136

Answers (1)

Luis
Luis

Reputation: 12048

The getLastKnownLocation() method returns the last GPS location acquired. If you don't start GPS location acquisition to have it acquiring new locations, the value returned by this method will always be the same old value.

You will need to:

  • Register for location updates with lm.requestLocationUpdates()
  • Define you onLocationChange() listener to receive the new locations
  • Add permission android.permission.ACCESS_FINE_LOCATION in AndroidManifest.xml file
  • Enable GPS utilization in phone setings

regards

Upvotes: 3

Related Questions