2

I'm trying to build an app using the GoogleMaps API and the user's location (once-off) and trying to find out how best to approach this but it seems like the approach the Stack Overflow answers take is very different to the approach the Android Developer site takes.

Basically the SO answers suggest subscribing to service that gives you location updates which you handle in a callback, whether you want the location once (like me) or actually plan to use the updated positions. (Post 1, Post 2, both highly up-voted)

However the Android dev site says you should connect a LocationClient and then just call getLastLocation() as you need it, which removes a bunch of the switching between sync and async coding elements.

So, I'm still confused as to what the "best-practice" way of doing this is and to why the Android dev site doesn't agree with the high-scoring answers here.

Community
  • 1
  • 1
Mike T
  • 4,747
  • 4
  • 32
  • 52

2 Answers2

2

Both the posts you've linked to are quite old (3 and 4 years old).

Android has come a long way in that time, and now we have an excellent Location API as part of the Google Play Services that you should use to get the user's location. This would be the current best practice.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
0

Android provides 2 ways to get GPS location. LocationManager and LocationClient. LocationManager has a request callback type and a get last known location. LocationManager has inherent issues. Some phones dont report back the callback at all, nor do they return back the Location from get last known location. LocationManager also uses a lot more battery.

LocationClient is the new and best way currently. They also use much lesser battery.

Siddharth
  • 9,349
  • 16
  • 86
  • 148