What is the difference between LocationClient and LocationManager.
What is the pros and cons between them (like battery, accuracy)?
Which is better to use?
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.
I have been developing a location based application in android and I seriously NOT recommend using the LOCATION CLIENT in any case. Reasons :
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)
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
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.
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:
It is quicker and more reliable.
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.
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:
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.
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...)
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.
Related
I am working on an app that needs to access GPS status, and obtain data about visible satellites like Constellation type, is it used in position fix, Elevation egress etc. I've been using Android Framework Location API that has classes in android.location package for that, especially GnssStauts. Now, I see that Google recommends switching to using Location Services API from Google Play services because it does a lot of things instead of us (Geofencing, Activity Recognition...), and is more energy efficient and I understand that, I have started using it for getting user location. But, I cannot find out how to use it for more complex needs, like getting GPS satellites data, like I described in the beginning. Am I missing something very obvious here, or Google still didn't cover that type of use cases with new Location Services API (but forgot to mention that anywhere in documentation), so for that cases we should still stick to good old android.location framework?
THe Location Services API are an attempt to not use GPS, but try to calculate from additional sources like wifi, cellular signals, etc to save from having to power on the GPS chip. Generally its more accurate than network but less than GPS. (Technically I believe it can be forced to use just GPS, but it isn't the normal way of using it). If you need actual GPS data about satellites, it isn't going to help you. If you need to run on non-Google approved devices, it isn't going to help you (unless they pirate Google Play Services). For your usecase, I would skip it and just use the built in location code.
Just simple as that.I dont want to find new coordinates every 10 minutes or meters.I just want to click a button and get my coordinates for this exact moment/place where i am.Every tutorial i've seen its old.New android versions require permissions to use GPS or Network.I am trying to implement those but nothing seems to work.
Any solutions?
Thanks in advance
I just want to click a button and get my coordinates for this exact moment/place where i am
That's not possible in general. The device may not know the user's "coordinates for this exact moment/place". You are welcome to call getLastKnownLocation() on LocationManager, or perform equivalent sorts of lookups with Play Services' fused location provider, but they may return null. Usually, to find out where the user is, you request location updates, then react when you get a location fix.
Every tutorial i've seen its old
These sample apps (for the fused location provider) and this sample app (for LocationManager), from my book, should be up to date.
New android versions require permissions to use GPS or Network
All Android versions require permissions to determine the user's location, for blindingly obvious privacy reasons. This has been the case since before Android 1.0, and it should remain the case for the foreseeable future.
I am trying to implement those but nothing seems to work
Then ask a fresh Stack Overflow question, where you provide a minimal, complete, and verifiable example demonstrating your problems.
I am trying to get an accurate location for my emergency alert app. I am already using the locationManager to get the location but fetching location with this technique takes about 30seconds I am looking for faster & accurate way.
The main goal here is to get faster/accurate location (Indoor or outdoor).
I have decided to use GooglePlayservices API for this purpose. I figured out there are two options LocationClient and GoogleApiClient?
I am not sure what is best here? Can somebody tell me what is the difference with both or is there a better option?
Let me know!
Thanks!
The GoogleApiClient location client is good if you need a fused high accuracy location.
With fused I mean a location calculated using Wifi, GPS and so on.
With the location client, instead, you have to select a provider. You can even use a criteria, but in this case I think the information is not "fused". In your case I think the best choice is to use the GoogleApiClient location client and you can use getLastLocation().
I would recommend to use GooglePlayServices, not only by the reasons #gresywolf82 hasstated, but also because it is most stable way of getting Location data.
In my experience I have encountered that some Android Devices may have issues obtaining location from the SDK's locationManager, this is due to probable bugs in the SDK, you can check an issue in the Android Open Source Project - Issue Tracker regarding this problem with the locationManager here
I have found the previous problem myself while using the locationManager and had absolutely no issues when switching to Google Play Services API.
SO in conclusion, not just for more precision but also for better stability within various devices I definitely recommend using Google Play Services API.
Both LocationClient and GoogleApiClient provide fused locations.
It is the LocationManager where you need to specify your own providers, this is a low level access if you want to roll your own.
As far as I can see, the GoogleApiClient is an aggregate of LocationClient and other GoogleApis (someone pls. correct if I'm mistaken). If you only wish to target LocationClient you may do so without any Activity compliance.
On the other hand, it would appear that GoogleApiClient requires tight coupling with the Activity life cycle, needing to be disconnected onStop and connected onStart. The trouble I have with such asynchronous calls is trying to make sure the API is up and ready by the time I need it. Therefore I usually go with LocationClient and keep it running outside of Activity lifecycles.
This works, but if you have issues with power consumption you may want to disconnect when app is in background, and reconnect when app comes into foreground.
Do not use GoogleApiClient. It is old and problematic. Use the new API. Please read the following Android newsletter link for the details :
https://android-developers.googleblog.com/2017/06/reduce-friction-with-new-location-apis.html
I newbie in location and trying make service to show my current location and another one location saved previously. And what the difference of using LocationListener vs LocationClient?
The LocationListener connects to the LocationManager and retrieves your location. This worked and works fine.
The LocationClient is a new way to implement this while some of the rest gets deprecated. It features more functions.
Both methods actually works.
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.
You can understand that since LocationClient is the latest, it is more efficient in getting the location with minimal energy(battery drain) with greater accuracy.
Reasons to use LOCATIONCLIENT because:
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)
The location client wont work on modified android versions of the android OS, as it requires Google play services.
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.
Note : There is no point of saving battery if you are not even getting your current location in a location based application.
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.
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.
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.