0

I need to get current position with the highest accuracy on user requests. He presses a button - app saves start location, he does it again - it saves stop location.

I decided to use Location Client from Google Play Services. But I'm still wondering whether I need to keep method onLocationChanged(Location location) updated all the time, according to setInterval time?

Maybe I should change interval? Or after getting start location removeLocationUpdates() and then requestLocationUpdates() again ?

I also tried with getLastLocation() but without requestLocationUpdates() each time I got the same coordinates.

Perhaps in this case LocationManager will be better? It has methods like requestSingleUpdate() or requestLocationUpdates() + removeUpdates() ?

Tomasz Ceszke
  • 171
  • 1
  • 10
  • You should not forget that to receive highly accurate location you need to use GPS_PROVIDER, which always requires at least 15-20 seconds to launch and establish connection with satellites. If accuracy is important and you cannot wait for GPS connection, you should receive location updates all the time and store last accurate location in some object to have possibility to achieve it immediately. – Alex Salauyou Mar 26 '14 at 20:35
  • Thanks for your comment. Right, in my case GPS_PROVIDER is a must. Just wondering whether I really need onLocationChanged(Location location) periodically updated by LocationListener if I need position only on request? Would be nice to have getLastLocation() working... – Tomasz Ceszke Mar 26 '14 at 20:57
  • Have a look at my answer to this question: http://stackoverflow.com/questions/19365035/location-servise-gps-force-closed/19366773#19366773 you can use the GPS first fix callback as demonstrated. – cYrixmorten Mar 26 '14 at 21:00
  • @tomek by getLastLocation() you just receive some location that is stored in cache on previous request, by your or other running apps. Very often it is outdated, you can check the time it was obtained by location.getTime() – Alex Salauyou Mar 26 '14 at 21:02
  • @cYrixmorten thanks, seems very promising. – Tomasz Ceszke Mar 26 '14 at 21:07
  • No problem, have used it with great success myself – cYrixmorten Mar 26 '14 at 21:08
  • @Salauyou But if I want to get position on user request, not on location changed event then what I should call ? I guess that: 1. use requestLocationUpdates(...) 2. keep onLocationChanged(..) empty 3. call getLastLocation(...) on user request. Right? – Tomasz Ceszke Mar 26 '14 at 21:12
  • @tomek.ceszke just create one Location object and overwrite it on every onLocationChanged() event, use its data when user requests. – Alex Salauyou Mar 26 '14 at 21:20
  • @tomek.ceszke when GPS is active, it sends location updates frequently enough not to be worry that it is outdated. You can manage frequency and accuracy by requestLocationUpdates() arguments. And you can always check the time it was received as I mentioned before--to make sure that last location is exactly what you need. – Alex Salauyou Mar 26 '14 at 21:28
  • I see. Just thought that getLastLocation does the same. Thanks again! – Tomasz Ceszke Mar 26 '14 at 21:29

0 Answers0