I work on an app that uses location data, and it needs to work in China. Android devices sold here largely don't have Google Play API installed at all and the only way is to root the phone to install it. So I'm stuck with LocationManager which works far worse than LocationClient (part of Google Play API).
My issue is that LocationManager, when reading from GPS_PROVIDER, frequently cannot connect to enough satellites (in China) and there's occasional significant time gap between fixes. When reading from NETWORK_PROVIDER, I can get more frequent fixes, however accuracy ranges from 30 to 500. Nowhere near LocationClient API quality.
The app is supposed to monitor your movement through streets frequently, eg. update every second (high battery use, not a problem to my client) and do something when you reach certain locations.
If I use Google Play API and LocationClient, it's really working well. But that's only on Nexus4 or some non-Chinese Android device.
I'm asking if anyone know a library that can give better results than straight forward use of LocationManager, or a solution how to use LocationManager to improve results?
GPS isn't working well likely due to lack of required GPS metadata (ephemeris and almanac data), or due to slow acquisition of this metadata. For the latter case, in most countries GPS ephemeris and almanac data is available through network sources.
If not, the GPS chip has to download that from the satellites which can take 5-20 mins (the fastest time being when the initial data stream provided enough info for the GPS chip to acquire a lock). I am not familiar with the availability of this data in China through network sources, but it sounds like it is not widely available from what your are experiencing. (Keywords to google for more info: SUPL, ephemeris, alamanac).
When GPS is not available or slow to get a lock, network geolocation is the fallback, which uses wifi points and cell towers to triangulate a position. This requires an internet service for the device to send the APs + towers it sees, and the service sends back a location.
Accuracy levels of 30 to 500 meters are quite good for this.
(BTW, a network geolocation position is also used to 'seed' the GPS chip to help it to get a faster lock)
Network geolocation on Android is typically provided by a google web service, but the phone can be configured to use other providers by carriers.
You can avoid using Google (Google Play or Google's network geolocation server) or the built-in network location service by trying Mozilla's free-for-use network geolocation service:
https://location.services.mozilla.com/
You need to request an API key: https://location.services.mozilla.com/api
For a code sample: this app both contributes data and is a client for the service: https://github.com/mozilla/MozStumbler
I doubt this will get better network geolocation accuracy for the area you are in, since you are already getting good results, but perhaps it is worth investigating.
Related
I have a mobile app (iOS and Android) that pings the location ~ every 15 seconds and is used in urban areas.
From my understanding
If Wi-Fi is disabled the app will use just GPS for location
If Wi-Fi is enabled the app will either use a mixture of Wi-Fi and GPS or just Wi-Fi
Generally Wi-Fi on drains more battery however if you are tracking location then it might actually save battery since GPS is more battery intensive than Wi-Fi (I think!)
Does anyone have data if enabling (but not connecting to) Wi-Fi will be better or worse for battery life?
Enabling WiFi should be good for battery life, but it depends entirely on how your application is coded. If you take a look at Android's page on Location Strategies, it says: 'GPS, Cell-ID, and Wi-Fi can each provide a clue to users location. Determining which to use and trust is a matter of trade-offs in accuracy, speed, and battery-efficiency.'
It is possible to get the location from just WiFi (yes, unconnected!):
netLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
but this may not be the most accurate solution. GPS uses a fair amount of power, but is obviously more accurate than WiFi, and searching for unconnected WiFi hotspots also takes power. In other words, this is a very complicated question.
All in all, the best solution (to avoid spending all your time coding this location stuff) is just to integrate Google Play services into your app. You can then specify the priority of finding the location (power or accuracy) and Google will sort it for you (check this out or the official google docs here).
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(15000);
mLocationRequest.setFastestInterval(5000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
protected void startLocationUpdates() {
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
#Override
public void onLocationChanged(Location location) {
mLastLocation = location;
}
The other priorities are PRIORITY_BALANCED_POWER_ACCURACY, PRIORITY_LOW_POWER, PRIORITY_NO_POWER.
However, back to the question. If we look again at Android's page on Location Strategies and scroll down, it says: 'Depending on the environment where your application is used or the desired level of accuracy, you might choose to use only the Network Location Provider or only GPS, instead of both. Interacting with only one of the services reduces battery usage at a potential cost of accuracy.'
From this, we can draw that using both WiFi and GPS gives a more accurate location than using just one, but that using just one uses less power than using both. HOWEVER, this depends on the environment. Since your app is designed for use in URBAN environments, it is often harder to get GPS signals (due to buildings). But getting a location from WiFi alone does not work all of the time (even in urban environments). However, for your app, since it is used in URBAN environments, I believe that using WiFi AND GPS will be the most power-efficient option for you, because sometimes GPS may not be available or will take a long time to connect (in urban environments). Remember, in urban environments people may lose GPS (e.g. they go into a store or into a very narrow alleyway). But if you have WiFi, you'll hopefully still be able to have their location. Another possible option to think about is trying to get their location using WiFi only at first, and then try GPS only if you can't get their location using WiFi. But this depends on how accurate you need their location. All in all, just leave it to Google (as shown above).
In answer to your question, it depends on how you're finding the user's location. I've suggested how to code your app, but if you want to leave it as it is, please post or comment the code you are using the find the user's location so that it can be determined which option is more efficient.
EDIT: I've seen that this is about iOS as well as Android. iOS provides much less control over how the location is determined. You just plug in the desired accuracy and Apple do the rest. Apple will determine the most power-efficient way of getting the location, and the same stuff that I've written above applies. Anyway, Apple will prompt users to turn on WiFi if it is disabled when getting the location, so trying to prevent use of WiFi for location on iOS is pretty much impossible.
GPS power consumption is extremely high compared to WiFi. Most phone lasts less than 10 hours on GPS while with WiFi they can last more than day.
WiFi is not only for location or the internet, it has multiple uses,
if you are using older os than Marshmallow, you can't disable all functionality to use WiFi while it is on.
from Marshmallow you can enable it for the specific use like location only.
so it will consume less power than GPS.
while in the prior version, GPS is in winning condition in power consumption.
https://android.stackexchange.com/a/127571/116948
I don't have any hardcore data on the subject, and doubt anybody will have any concrete numbers, but theoretically Wi-Fi will be far better than GPS only. The theory works something like the following: In order for a GPS to know where someone is at, it needs to receive information from 3 different objects at known locations and use triangulation to figure out its location from that, whereas wifi only needs to make one call, to the nearest internet repeater, which has a known location and known path. In order to assure accuracy this is often done multiple times with each location request. Thus the extra calls add up and Wifi will be more efficient.
Use WiFi whenever you have access to a network because it uses less battery than GPS. (Shorter distance, lower power.) Turn WiFi off when you don't have access to a network, otherwise it will keep looking for a WiFi network it can use (which drains battery).
Here Google says:
The Google Play services location APIs are preferred over the Android framework location APIs (android.location) as a way of adding location awareness to your app. If you are currently using the Android framework location APIs, you are strongly encouraged to switch to the Google Play services location APIs as soon as possible.
Can anyone explain to me why(if I) need to switch to the new APIs?
I think that the core difference is that FusedLocationProvider use the both physical sensor and google play service, where as other (location manger /location listner) use physical senors like gps and network.
FusedLocationProvider
FusedLocationProvider uses a combination of hardware and google play service, to found the context(location) of the request.
Pros:
It provides better accuracy with less battery drain, as it switches between gps and WiFi based location.
optimized transparently to you.Avoid heavy processing by using cache of location.if user has many location aware apps than it will not waste time and resources for waiting to get new location and use the previous location.
Google Play Services 3.2 includes several enhancements to the Location Based Services. The Fused Location Provider now supports the selection of a low-power mode option when requesting location updates, and the ability to inject mock locations — allowing you to more efficiently test your apps in a variety of simulated conditions.blog
When desiring to save battery power, and using coarse updates, the FLP doesn’t use Global Positioning Services (GPS), and instead uses WiFi and Cell tower signals.
Fused API provides 3 location providers.
HIGH_ACCURACY mode use all location providers
BALANCED_POWER mode exclude gps
NO_POWER mode use location from other apps
Cons
Location manger , use gps although it takes battery yet its work great without network.
Indoor accuracy is still a question mark , as if your using apps in indoor its accuracy is not good.
location manager is slow but accurate with gps , its a trade-off between accuracy and battery consumption.
If you plan to release it on Amazon, F-Droid or anything other then the Play Store, use the LocationListener or implement both. There are quite a few people who don't want Google to track their every move
To me the more accurate is Location Manager as it use in all platforms no need of google play store. but it takes some time and location detection speed depends on some factors such as you are on open place or not , weather etc
Related Material
I am a user of mapy.cz, Czech mapping portal that also happens to have an Android app. I guess that both the browser version and the mobile app obtain the current location from an API, the HTML5 API or an Android API. My current understanding is that in the end, both APIs talk to the "Google Location Service / Database", right?
Now, how comes that the mobile app reports a correct location while the web version reports a location a few kilometers away? My phone has of course GPS turned off to make those two scenarios comparable. Both the PC and my phone are connected to the same WiFi network at this moment. Shouldn't both APIs report the same location? If not, what makes them different? I'd like to understand this, thanks.
Geolocation of a wifi adress i never 100% accurate, the city of an ip adress accuracy is between 50-80%, nation 98-99%, down to zip code or adress is even less, so you will get different results depending on what service you are using, and you can get different outcomes every time you use a single service, since it's not accurate, not like GPS that can track you to mm distances.
Edit: your mobile phone is probably more accurate because the service probably triangulates via mobile masts as well as IP
So I am working on this app that will get the location of a wifi hotspot by just detecting it using the sensor wifi of the phone (The phone is not actually connecting to the hotspot wifi, it just detect).
I was doing some preliminary research before start developing the app, and it seems that the Google Geolocation API will do the work for me. However, it is not free (at least what I understood after reading through the API). I had checked other apps that detects wifi hotspot, and I am just wondering if those apps have their own database with all the wifi hotspot information (SSID, location coordinates, etc) so when the wifi sensor detects a wifi hotspot, it will lookup the database and get the information such as location.
Also, I was mentioned by a colleague that Google Maps also stores wifi info. Is is true? Cause I couldn't find any info about that.
Android has multiple LocationProviders, including:
LocationManager.GPS_PROVIDER : get position using GPS
LocationManager.NETWORK_PROVIDER : get position using Wifi, cell network, etc.
LocationManager.PASSIVE_PROVIDER: get position using data provided by already running providers. This allows several apps to share geolocation information)
You don't have to pay anything to use NETWORK_PROVIDER
Some providers might not be present on all devices, depending on phone model and android version.
Providers have different characteristics: NETWORK is fast but not always precise enough, GPS is precise but slow and battery intensive, etc. The best strategy is to request location from several providers, and cancel pending request as soon as you get a location that is good enough depending on your criteria (precision, response time, etc.)
I found this article by Reto Meier quite useful to wrap my head around geolocation on Android
I try to receive latitude & longitude on android phone.
Is location on android receive directly from satellite?
Why it dynamic all the time, while I standing though?
So, anyone know how to make it stable ?
Thanks
The location may come from a variety of places:
The "last-known" location, an OS-level cached location (fast, but may be inaccurate)
The wifi network (Google can often deduce location from the wifi net you're on, but not always)
Mobile network - if the device is on a mobile phone network, that can provide location information
GPS receiver. If the device is outdoors this will provide the most accurate location
Your app will have specific needs, and so you need to decide which locations you want, and what you do when you get them, based on their accuracy, and the source.
With GPS, buildings, tees, the weather, etc will all have an effect on the location, so you'll never get one amazingly accurate location. Many apps just request a location and use it, but if you need accurate, stable location data, you need to collect data from relevant sources, and then use your own algorithm to decide which to use.
You need to read, understand, and use what's in this page:
http://developer.android.com/guide/topics/location/obtaining-user-location.html