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.
Related
I'm developing an android app fully based on user location, so I would like to receive the coordinates as frequently as possible. For this case I decided to create a service that will run in the background (looping) and use user GPS and NETWORK providers every 10-15 seconds and after it received a fix, turn them off. Is it a good practice?
When you are convinced that you need user accurate location and you need it to be update then you need it. However you can take a look at this answer to understand preferred manner to implement it (of course with a little change)
And please consider using Google Fused Location :
The Google Location Services API, part of Google Play Services, provides a more powerful, high-level framework that automatically handles location providers, user movement, and location accuracy. It also handles location update scheduling based on power consumption parameters you provide. In most cases, you’ll get better battery performance, as well as more appropriate accuracy, by using the Location Services API.
Refrence
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 have two different classes in my application that implement LocationListener. One of them is only used as needed to get the user's current location, while the other is constantly run in the background to keep data on the user's speed.
On my test device, this causes no problems. Some other people testing however have said that their device "locks" (I have not seen this occur, so I'm unsure what they truly mean by this) when trying to acquire the location.
Is it possible that this is just their phone having a weak GPS fix, or could this be some weird hardware issue that occurs when two different threads are trying to gain the location via GPS? If so, what's the best way to work around this? Thanks.
I would suggest you use the new fused provider that is part of Google Play Services. I would not set two LocationListeners. Since you will be constantly tracking the user's location, by using the new LocationClient you can use its getLastLocation() to retrieve the most recent best, cached location the device has, which is really likely to be one from the constant updates you are already retrieving. The fused provider will also determine which one is the best provider to take the location from, you do not need to worry about that logic.
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.