1

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!

ssgao
  • 5,151
  • 6
  • 36
  • 52
  • http://stackoverflow.com/questions/6166317/why-does-the-locationmanager-does-not-have-a-lastknown-location?rq=1 – NickT Oct 13 '12 at 23:29

1 Answers1

3

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

Luis
  • 11,978
  • 3
  • 27
  • 35
  • Thanks a lot. I used lm.requestSingleUpdate instead, since i only want it to execute once – ssgao Oct 14 '12 at 01:09
  • Hello, I'm stuck in Location, in this case location manager return same location each time, I have do all things which u mention above. But still i get same location in gps tracker – Mihir Lakhia Oct 28 '15 at 05:45