Google maps - distanceTo vs proximity alert vs geofence - android

I'm building an app for mobile which needs to monitor the distance between the user's location and multiple location markers at regular intervals. From what I have read here and on other sites, I have three options:
1) use the distanceTo and distanceBetween functions to calculate the distance between the user's location and each location marker
2) use proximity alerts associated with each marker location
3) use geofences associated with each marker location as per Creating and Monitoring Geofences
Which approach is the best to use in light of (a) ease of implementation, (b) battery drain, and (c) gps / location accuracy? Given that I am designing predominantly for mobile, I am assuming that wifi will not always be available.

An important note on the Google Play GeoFencing API. I've found that the GeoFencing never intelligently retrieves locations from the GPS hardware. The GeoFence API will observe the most accurate location available from the OS or if no recent location reading is available, it will cause a location to be calculated from Wifi / Cellular. (which sucks because cellular is wildly inaccurate and wifi is often unavailable)
So to get at all responsive or accurate results out of the Geofencing API you have to set up your Geofences and then poll the GPS hardware on an interval, not even doing anything with the result received, so that under the surface you are providing worthwhile data to the OS.
I can't speak specifically to the behaviour of LocationManager.addProximityAlert but I doubt it behaves any differently. You could really use either and the results and performance will likely be identical because the heavy lifting is done by waking up the GPS manually.
As for how to implement your current distance to your fences, none of the proximity APIs have an interface to determine this for you. In the situation I describe above when the GPS poll occurs, instead of doing nothing with the result, I'd use it with distanceBetween to update the distance between myself and the points I've set my GeoFences at.

Related

How does Apple or Android calculate speed in devices?

There are any documentation for this? I've checked many formulas and algorithms but didn't find an explicit definition how they get the speed provided in Geolocation object.
The GPS chipset provides the current velocity to the system along with the current location.
The chipset may compute the velocity by comparing location over time and correcting for the curvature of the Earth at the current location, or from the Doppler shift of the received satellite signals.
Whichever method is used, the operating system doesn’t need to do any processing to get the speed. The velocity data is provided along with location and altitude data directly from the GPS chip (actually chips in many newer devices support both GPS and GLONASS, but which system is used is not visible to the user).
Physics.org has a simple explanation of how GPS works
Wherever you are on the planet, at least four GPS satellites are ‘visible’ at any time. Each one transmits information about its position and the current time at regular intervals. These signals, travelling at the speed of light, are intercepted by your GPS receiver, which calculates how far away each satellite is based on how long it took for the messages to arrive.
Once it has information on how far away at least three satellites are, your GPS receiver can pinpoint your location using a process called trilateration.
But you can search for more detailed explanations of the mathematics and physics involved.
It basically scans your location (i.e. your latitude and longitude) and compares with the last check. Using euclidian distance, it can get the distance in the period of time. With the time (for example, if it scans your location every 2 seconds), it can easily estimate your speed by doing Speed = Distance/2.

Android GPS location accuracy issue

I am working on gps tracking apps in android. Here is my code architecture:
BackgroundSyncService : A service class that is used for getting location update. Here GoogleApiClient is initialized and implements others Location related methods.
AppRunCheckerReceiver : A BroadcastReceiver class that will check if my BackgroundSyncService is running or not in a time interval. If it stopped then it start.
GpsEnableReceiver : A BroadcastReceiver it will fire if gps status changed. It will check if my BackgroundSyncService is running or not in a time interval. If it stopped then it start.
InternetConnectionStateReceiver : A BroadcastReceiver it will fire when internet status changed. It will check if my BackgroundSyncService is running or not in a time interval. If it is stopped, then it start.
In my BackgroundSyncService service I initialize the GoogleApiClient using this way:
public void setLocationLocationRequest() {
try {
googleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(com.google.android.gms.location.LocationServices.API).build();
locationRequest = new LocationRequest();
locationRequest.setInterval(3000);
locationRequest.setFastestInterval(3000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
googleApiClient.connect();
} catch (Exception e) {
}
Here accuricy is LocationRequest.PRIORITY_HIGH_ACCURACY and interval is
locationRequest.setInterval(3000)
here is the GoogleApiClient implementation code.
This application GPS info section contains Latitude longitude and Accuracy parameter
My Findings: in onLocationChanged(Location location) method I check the accuracy of Location object in this way : location.getAccuracy(). Here if accuracy is less than 50 meter, then I accept it.
In 85% of the cases it working like a charm. It sending me exact location from GPS. But in 15% cases, it sending me inaccurate location like more >300 meter.
The 15% device are low cost China brand mobile.
My Questions:
How can i make accuracy level near 99%. Is there any problem on my code architecture?
Does GPS accuracy depends on device configuration? if YES then what can I do for low configuration device?
How Uber, Go-JEK etc. ride sharing apps works for all device? Is they have extra coding for GPS only?
My application is for Bangladesh. Here internet is slow. Is it has negative impact on GPS accuracy?
Thanks in advance for this thread. And also sorry for bad english.
How can i make accuracy level near 99%. Is there any problem on my code architecture?
This is real life scenario. You cannot ensure that all the location providers will work as expected. You should ask for best available position.
a) Does GPS accuracy depends on device configuration?
YES. Some devices may have older GPS chipsets which can only track GPS signals (USA) since there are other positioning systems like Galileo (Europe), GLONASS (Russia), QZSS (Japan) and Beidou (China). The more the chipset support for these types the more chance you get to track more satellite hereby position fix. Also TTFF (time to first fix) depends on how many channels do the gps receiver has.
b) If YES then what can i do for low configuration device?
Since this is a hardware issue, you cannot do anything here. But other location sources can compensate the lack of GPS data such as AGPS (aided gps), wifi and cellular positioning. Also there are some paid options which provides a database to locate your device using wifi access points and cellids (they claim that they provide best solution on wifi but i m not sure as I dont use it. you can check it out http://combain.com). Wifi and cellid also depends on how many wifi access point and cell tower available around and how far they are (signal strength). If you need 50m accuracy, cellular positioning has nothing to do but wifi has a chance to get closer to this value.
Some study results from 2009 [3]
3G iPhone w/ A-GPS ~ 8 meters
3G iPhone w/ wifi ~ 74 meters
3G iPhone w/ Cellular positioning ~ 600 meters
How Uber, Go-JEK etc. ride sharing apps works for all device? Is they have extra coding for GPS only?
They may have specific Location strategies but it will based on using other sources during GPS outage.
My application is for Bangladesh. Here internet is slow. Is it has negative impact on GPS accuracy?
Other answers claims that internet is not related to GPS. Yes it is true it is not related to GPS but location. AGPS uses internet to fetch 3 types of data (Satellite signals, almanac and ephemeris) which assist GPS to provide position fix faster. If ephemeris and almanac are outdated or the device moved several hundred km from the previous position fix then it is called cold start and takes around 12-15min without AGPS.
Fused location provider already knows how to provide best solution with these configurations, so you should bless it.
References:
[1] http://gpssystems.net/agps/
[2] http://gpsinformation.net/main/almanac.txt
[3]
https://communityhealthmaps.nlm.nih.gov/2014/07/07/how-accurate-is-the-gps-on-my-smart-phone-part-2/
First, (and second)
How can I make accuracy level near 99%. Is there any problem on my code architecture?
Does GPS accuracy depends on device configuration? If YES then what can I do for low configuration device?
Both - device configuration and code architecture, are important here. If you are already at an 85% success rate, the code architecture is alright I think.
As far as GPS goes, line-of-sight is an important factor when it comes to device configurations and accuracy.
Although a low cost mobile could return an accurate location with a clear line-of-sight. You can try running 2 cycles more/waiting to attain higher accuracy.
In a worst case scenario and for what its worth, you can also try retrieving location using the LocationManager and GPS provider technique which works as a fallback in the 15% just to compare and ensure you are using the most accurate location you can get.
Location Strategies put it as
In most cases, you'll get better battery performance, as well as more
appropriate accuracy, by using the Location Services API.
How Uber, Go-JEK etc. ride sharing apps works for all device? Is they have extra coding for GPS only?
They do work but not always with highest of accuracy for locations received within the app. If there are any location hacks for us developers, we need to find them, maybe a 5th page google search result :) or benefit from the open source environment. For me, best practices and android repo links suffice. You have already followed posts like Receive location updates
My application is for Bangladesh. Here Internet is slow. Is it has negative impact on GPS accuracy?
No relation between Internet and LocationManager + GPS_PROVIDER

Is Fused Location Provider good choice?

I am developing an application where I want to use Fused Location Provider. But I have some doubts, and couple of questions.
When GPS is off and I set priority to HIGH, does that mean that the GPS will be automatically turned on, or not?
Can I set UpdateLocation with Fused provider with HIGH priority on demand to save battery at least a little bit?
How can I know what Fused provider is using (is it a GPS or a network provider)?
And finally
Is Fused provider really the best choice for android location? Are there any negative points about it?
What is your opinion?
Thanks in advance.
When GPS is off and I set priority to HIGH, does that mean that GPS will be automatically turned on, or not?
No, it will not be turned on automatically. But if you use SettingsApi, will prompt a dialog to user and gives information that GPS is must be turned on. If user accepts it, the gps will be active automatically. Check the SettingsApi
How can I know what Fused provider is using (is it a GPS or a network provider)
If you use fused provider api with SettingsApi properly. It will make adequate the required settings for current location request.
Is Fused provider really the best choice for android location? Are there any negative points about it?
In my opinion, before fused provider you must deal with directly providers(Gps, network) But fused just asks you, "how accurate locations you wanna receive ?"
As in here https://developer.android.com/training/location/index.html stated very clearly that, 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. So I hope you got your answer.
I made a testing application for Gps, Wifi and Fused Location Provider and testing it for 2 days. It's better because it uses both of them and most of the time it's the one most accurate. Also, Gps data is a very noisy data that causes jittering, to solve this low-pass filter or other filters are used. One of the most successful filter used to get most accurate results is Kalman Filter. FusedLocationProvider use this filter same as RotationVector which is a fused sensor combines hardware and software. RotationVector uses accelerometer, gyroscope(if available), and magnetic field sensor to get and filter positition and azimuth data.
Location.getProvider for Gps with LocationManager returns "gps", Wifi returns "network", and FusedLocationProvider returns "fused".
When GPS is off and I set priority to HIGH, does that mean that the GPS will be automatically turned on, or not
Anything other than "Battery Saving" turns Gps on if available. This settings available on my Android 7.1.1 phone. Setting for location was different on previous versions of Android on user's side. As a developer to enable using Gps you should set mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
PRIORITY_HIGH_ACCURACY - Use this setting to request the most precise location possible. With this setting, the location services are more likely to use GPS to determine the location.
Setting Priority also determines battery use level too.
Can I set UpdateLocation with Fused provider with HIGH priority on demand to save battery at least a little bit?
Yes, you can set interval of location request in addition to priority.
mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
How can I know what Fused provider is using (is it a GPS or a network provider)?
Location from Wifi never returns true for Location.hasSpeed() but Gps returns almost always true if you are outdoors. Also location.getExtras() have satellites tag which you can check for satellites which is only available for Gps. Speed may not be correct if you are walking or as far i've read so far, i haven't tried this on car, when speed it less than 5km/h it's not very accurate. I mean if you are using FLP and last location data contains speed info it's definitely from Gps.
Are there any negative points about it?
As of Android 8.0 and above there is location retrieving limit if you do not use a Foreground Service or get location on foreground while app is not paused for both FLP and LocationManager.
Also FLP requires GooglePlayService to be available on user's device and it should be above a particular version. 10 or 11 depending on which one you use. This can be trouble if you wish to publish your apps on a country, for example China, that bans Google Play Services.
The existing answers don't say why the FusedLocationProvider is better.
It is better because the API fuses from more data sources (sensors, wifi, context, history) in an intelligent and battery-saving way. Also, Google is always improving it by adding more data sources. If your app uses it, you get those improvements for free.

How does the fusedLocation API interval relate to turning off the GPS radio

Let's assume I'm used the Android fused location API to request highly accuracy location reporting. For example,
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(FASTEST_UPDATE_INTERVAL*2);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi
.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this)
This results in my location listener getting called up to every FASTEST_UPDATE_INTERVAL. If I set FASTEST_UPDATE_INTERVAL to be short I know that the GPS radio will not be turned off between location updates. I know this from various sources such as Fused Location Provider unexpected behavior and https://www.quora.com/Why-does-GPS-use-so-much-more-battery-than-any-other-antenna-or-sensor-in-a-smartphone.
My question is what is the smallest value of FASTEST_UPDATE_INTERVAL that will result in the GPS radio being turned off between location updates?
I anticipate there will not be a clear answer to this question, and that it will depend on the phone hardware, the Google Play version and probably other hardware and software factors. Nonetheless a general answer would be helpful.
This question is important because I am interested in using high accuracy locating but minimizing battery use. To a point I am happy to increase FASTEST_UPDATE_INTERVAL if it will save power.
Wouldn't it be nice if the google fused location services used the device's motion detectors (if they exist) to work out when it was stationary and if so simply turned off the GPS radio until the device moved.
Even if you found an answer, I wouldn't count on it remaining the same between devices, OS versions, or Google Play versions. If you absolutely don't want GPS, don't used the fused provider. Use the network provider from the base LocationManager.
As for using motion detectors- they don't exist. It has an accelerometer, but to an accelerometer staying still and traveling at a constant 50mph look exactly the same (traveling at constant speed is 0 acceleration). It might not be a good optimization anyway- getting a lock on multiple GPS satellites takes several seconds. You don't want to keep turning that on and off if someone wants accuracy.

Is there any idea to get altitude data quickly while using LocationClient for Android?

I have been using LocationManager for Android to record location data, and the new 'LocationClient' API has come, so I tried it.
The result looked good. It gets location data very quickly, but I found that the Android Fused Location provider(LocationClient) doesn't provide altitude data in almost all cases, even though I tracked quite a long time.
So, the question is, 'Is there any nice way or idea to get altitude data while using LocationClient?', or should I just stay using GPS provider which is not fast enough?
AFAIK, the only provider today in standard Android that can give you altitude is GPS. AFAIK, both WiFi hotspot proximity and cell tower triangulation presume that you are on the surface of the Earth, or at least within a relatively narrow band of the surface, treating the local area as a flat plane.
LocationClient and the "fused" location provider is designed to blend all of those approaches to get you more accurate latitude/longitude more quickly. However, if my AFAIKs are correct, it cannot get altitude any faster than GPS. And, depending on how it handles things internally, it may put more emphasis on the non-GPS providers, and therefore give you altitude less frequently. Since the Play Services stuff is closed-source, we have no good way to know.
or should I just stay using GPS provider which is not fast enough.
The speed of obtaining GPS fixes is tied to environment (e.g., indoors/outdoors) and to device GPS receiver quality.

Categories

Resources