Search code examples
androidgpsandroid-mapviewprogressdialoglocationlistener

Fetching gps coordinates: continuously vs. single request


I have implemented a LocationListener activity to get the lat/lon coordinates. I launch a MapActivity and want to get the current location and show it on the map. Now I'm confused. What is the best approach to show a progress dialog while fetching the coordinates?

  • Start an activity for result (LocationListener) and show a progress dialog while waiting for the coordinates to be delivered.
  • Implement a getCoordinates() method in the LocationListener activity and just call it once i need it (in a thread?)
  • Include LocationListener into MapActivity and let it continuously update field vars from onLocationChanged()

Is there any better solution? I'm pretty sure there is, actually i don't really know what I'm doing right now... :-/


Solution

  • A good model for displaying location(s) on a map can be found on the android official guide. Check this, and scroll down to "Helping the user decide on where to go".