Differences of location services - android

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.

Related

How to use FusedLocation API to monitor location updates when app is not active

The FusedLocation API is newer than LocationManager API, but it is not clear to me when to use one vs the other. I want to monitor location changes even when the user is not running the app.
I found this nice example using the LocationManager but this is from 2011. Is this information still relevant?
The FusedLocation API examples show how to configure a LocationRequest for continuous location updates in your Activity. My question is, how would you use it to monitor location changes when your Activity is not running?
I've seen other examples that use Alarm Manager, but this is basically polling and seems like overkill and might drain the battery (but maybe I am wrong?).

GoogleApiClient Vs LocationClient to get accurate location in Android

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

Receiving current location on Android

I've been working on an app that needs to be location-aware, and I've noticed that there are two (or more) methods of receiving location: with Google Play services (as seen here developer.android.com/training/location/retrieve-current.html#GetLocation) and with Location Manager, Providers etc. (as seen here http://www.vogella.com/tutorials/AndroidLocationAPI/article.html#locationapi_criteria).
What is the difference between these methods (if there is any)? Which one is more accurate?
edit: ok, I see that I sent the wrong link on the first thing. Won't this code (http://developer.android.com/training/location/receive-location-updates.html) give me location updates? Generally, what's the most accurate way to get my location?
The one with the GPS is accurate and that which is based on Network is not. Google Play Service use FUSE api to get the GPS location first, if the location is found (that's great), otherwise it will try to get location fix from Network Tower. In Short the one with GPS is accurate
The first method provides the details of LastKnownLocation. ie. the last location received from GPS or network provider when you or other apps accessed the location services. After that there are chances you moved a lot and it need not be your current location. So if You are planning to create an application that requires accurate location tracing, You should fetch the location as in the "Vogella" method. If the current location is unavailable, you can try using the last known location (As a plan B :-)).

LocationClient vs LocationManager

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.

Android Location update

Im writing an android aplication in which is required the actual location of the user, but I'm having trouble acquiring that location.
I'm using a LocationListener to listen for the location update, via Wifi (NETWORK_PROVIDER).
The problem is I don't get an update, and I imagine it only happens when I change network. If I don't get updates, I can use lastKnowLocation but it does not provide me with the actual user's location.
Is there a way to force a location update, via NETWORK_PROVIDER?
Cheers
Even better, I suggest you look at the new Location APIs in Google Play Services.
There's a training class for them as well.

Categories

Resources