34

What is the difference between LocationClient and LocationManager.

What is the pros and cons between them (like battery, accuracy)?

Which is better to use?

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
nrofis
  • 8,975
  • 14
  • 58
  • 113

4 Answers4

34

Location Manager was introduced in Android SDK and can be used as a feature of android.

Location Client is something that's part of Google Play SDK and is introduced in the recent Google IO 2013.

One can understand that since Location Client is the latest, it is more efficient in getting the location with minimal energy(battery drain) with greater accuracy.

UPDATE: LocationClient is deprecated. You have to use GoogleApiClient. An example of it can be found here.

Google Play Services Team has cleaned up their code and moved LocationClient functionality into GoogleApiClient.

Tutorial for the same is available in http://developer.android.com/training/location/retrieve-current.html

On following link you can find IO talk about this subject http://www.youtube.com/watch?v=Bte_GHuxUGc

UPDATE AGAIN

GoogleApiClient has been deprecated again, you have to use GoogleApi based APIs instead.

Arpit Anand
  • 347
  • 2
  • 17
Naresh
  • 3,174
  • 1
  • 17
  • 22
  • 1
    Adding one informative sentence here: "LocationClient is for it to blend data from multiple sources (GPS, WiFi, cell towers, sensors, etc.).", Information courtesy: [Mark Murphy](http://stackoverflow.com/questions/17239006/android-locations-got-from-locationclient-doesnt-support-speed) – Paresh Mayani Mar 04 '14 at 12:42
  • All these features are used by LocationManager as well. LocationClient is just one good wrapper for LocationManager. You can create your own LocationManager Wrapper (i.e. your own LocationClient) and tweak it yourself – geekoraul Mar 27 '14 at 10:01
  • 1
    I believe they use sources from Google maps and so on which were not supposed to be open sourced. That's why they put that in Google Play Services. If they tweak them in Location Manager, they had to opensource the code underneath. Its a managerial decision in my point of view. – Naresh Apr 08 '14 at 07:45
  • As of now the new GoogleMaps don't give you immediate position. They have become worse than ever. If you compare them to the old GoogleMaps, the old versions ( like in Gingerbread ) were much more efficient in giving you quick location. – geekoraul May 20 '14 at 22:23
  • 1
    LocationClient is deprecated. I updated the answer to avoid show useless information. – MiguelHincapieC Nov 28 '14 at 21:29
  • @NareshR in one place your answer says `LocationClient is deprecated.` and at other `Location Client is the latest`. It is quite confusing. please elaborate. – Mohammad Tauqir Oct 09 '15 at 03:00
  • 1
    @Tauqir : Location Client class has been changed to LocationServices. The concept is the same. Its like LocationManager doesnot use Google Play service. While LocationClient used Google Play Services to get the information. Then In further releases, The Location Client has been moved to LocationServices. Use the link below to retrieve location using Google Play Services. https://developer.android.com/training/location/retrieve-current.html – Naresh Oct 09 '15 at 07:02
  • @NareshR, Thanks for clarifying and if possible please update the answer as well. – Mohammad Tauqir Oct 09 '15 at 07:19
  • Then why in http://developer.android.com/intl/es/guide/topics/location/strategies.html they use LocationManager? – Daniel Gomez Rico Feb 10 '16 at 15:52
  • If you dont want to depend on Google Play Services, use LocationManager. If you are OK to use Google Play Service, use GoogleApiClient. Note that you have the dependency that the User must have Google play service installed in the second case. – Naresh Feb 11 '16 at 07:24
15

I have been developing a location based application in android and I seriously NOT recommend using the LOCATION CLIENT in any case. Reasons :

  1. The location update behavior is very abnormal and wont work as you expect. i.e. The location updates get stuck when switching networks. (It keeps giving you some old location)

  2. The location client wont work on modified android versions of the android OS, as it requires Google play services.

With my experience, Location Client might be good on the battery of the phone but it won't be good with giving you timely accurate location updates.

I recommend good old Location Manager as I don't find location client reliable at all.

P.S. : There is no point of saving battery if you are not even getting your current location in a location based application.

EDIT: If you know the implementation of LocationManager and LocationClient (both are available in documentation), you can create your own LocationClient-like wrapper (with callbacks and stuff), which will be working on LocationManager but with custom tweakable properties.

EDIT 2:

Please find the LocationManager Wrapper class here, which provides timely location updates:

https://github.com/rahulsh12/LocationManagerWrapper

geekoraul
  • 2,623
  • 2
  • 21
  • 33
  • 2
    Can you recommend a good example/tutorial how to use the good old Location Manager to get periodical position updates e.g. in every ~1 minute? Thanks. – Blehi Mar 27 '14 at 07:38
  • @Blehi check out http://goo.gl/P7f3yZ for reference of how to use the old Location Manager – Paulo Henrique Nonaka Jun 19 '14 at 13:23
  • Thanks. I've created my own service but the "It keeps giving you some old location" problem still exists. Especially when switching networks (e.g. from GPS to WIFI and back). Do you also receive "invalid" positions sometime? – Blehi Jul 10 '14 at 08:23
  • If you have created your own location wrapper using LocationManager, you should check for old locations you get using the strategy/code provided here :http://developer.android.com/guide/topics/location/strategies.html – geekoraul Jul 10 '14 at 22:18
  • Wrapper over the LocationManager class added to provide LocationClient like API and reliable location updates. – geekoraul Nov 17 '16 at 06:30
3

I have worked on a tracking app and my experience is that LocationManager is better than LocationClient. LocationClient does not provide any way to specify that you want location updates from GPS only. All it allows is to specify "high accuracy". This works for most part but every now and then you get a location update which is hundreds of meters off BUT with a specified accuracy of a few meters. There is no way to know you got an unusable sample. With LocationManager if you specify GPS_PROVIDER you can be assured that you are never going to get wildly inaccurate samples. Working well for us.

everydayapps
  • 455
  • 1
  • 5
  • 20
2

Coming from someone who switched over to Google Play Services a while ago, i can give you some experiences:

I have an app, about 2,5 years old, that uses location services extensively. From the outset, of course, we used the LocationManager since that's what was available on the Android platform.

We had a pretty bad experience with Location Services on Android compared to IOS. It was buggy, unreliable, and gave less precise locations than than our IOS app, plus that it drained more battery. It was a drag.

Therefor, when Google unveiled the new API in june this summer, we jumped at it. It is way better. A couple of things:

  1. It is quicker and more reliable.

  2. It is less buggy. As an example, in the old API we could sometimes get an "old" fix with a new timestamp. This never happens anymore. There's more but it would be an even more lengthy post.

  3. It definitely drains less battery. For example, when you had a map view open, the GPS ran all the time, and the GPS icon was visible. This is not the case with the new one. This made users wonder what was going on. This is nolonger as big an issue.

So, when it comes to the location output and work, everything is better. But there are some downsides:

  1. You have to have Google Play Services installed, meaning it wont work on any "non-google-approved" phone models, and in some instances you'll have to tell users they need to install it.

  2. The API itself is more complex IMO, in part due to point 1. In addition to the "regular" callbacks i.e. waiting for location fixes etc. You now have a process that takes part before you can get started where you have to check that playservices is available, and "connect" the locationclient. This is extra code and a bit more complex to grasp. More faulty conditions to take into account in the code too (if you can be bothered...)

  3. Google play services itself requires at least 2.2 so it won't work for older devices than that. We had to tell some clients they had to upgrade...

Hope this helps.

Mathias
  • 3,879
  • 5
  • 36
  • 48
  • I am reading this: [ http://developer.android.com/reference/com/google/android/gms/location/LocationClient.html ] and there it says that LocationClient is deprecated. Any info on that? – Ted Jul 07 '14 at 10:00
  • Interesting. http://stackoverflow.com/questions/24611977/android-locationclient-class-is-deprecated-but-used-in-documentation – Blehi Jul 10 '14 at 08:35