It is possible to detect geofence events without requestLocationUpdates? - android

It is possible make the geofence exit and enter events trigger without any location request?
Even when there is no other application requesting location, only with the device GPS turned on?

Yes, it's possible. The device can know its location from the nearby wifis and the phone signal.
The location accuracy of these methods is not as good as with a gps signal stablished but if the radius is big enough as 150m or more as it's recommended in the geofencing docs this is enough. And bigger in rural areas:
Choose the optimal radius for your geofence
For best results, the minimum radius of the geofence should be set between 100 - 150 meters. When Wi-Fi is available location accuracy is usually between 20 - 50 meters. When indoor location is available, the accuracy range can be as small as 5 meters. Unless you know indoor location is available inside the geofence, assume that Wi-Fi location accuracy is about 50 meters.
When Wi-Fi location isn't available (for example, when you are driving in rural areas) the location accuracy degrades. The accuracy range can be as large as several hundred meters to several kilometers. In cases like this, you should create geofences using a larger radius.

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: What is the minimum and maximum radius for geofence

I am working on an Android app which makes use of geofence. I want user to decide the radius of geofence. But I want to know what is the minimum and maximum radius for the geofence so that app will work fine.
For best results, the minimum radius of the geofence should be set between 100 - 150 meters.
=> When Wi-Fi is available location accuracy is usually between 20 - 50 meters.
=> When indoor location is available, the accuracy range can be as small as 5 meters. Unless you know indoor location is available inside the geofence, assume that Wi-Fi location accuracy is about 50 meters.
Check and read developer site
https://developer.android.com/training/location/geofencing.html
You can set 50-100 meters as minimum for all conditions.
The documentation doesn't actually specify a minimum or maximum but while investigating some issues I found that geofences that are smaller than 80m radius seem to be added as 80m at least on my device. I found that out using:
adb shell
dumpsys activity service com.google.android.gms/com.google.android.location.internal.GoogleLocationManagerService
That said, it's seems a little inconsistent because they sometimes trigger an exit while I am well within the 80m - almost at the edge of the 30m that was the original geofence but other times it works differently. The adb command still shows 80m.
Maximum- the radius of the earth. GPS is confirmed not to work on the moon.
Minimum- depends on the accuracy of your gps hardware, atmospheric conditions, etc. If everything is great, probably 10 meters reliably. If you fall back to network location, probably about 500 meters.

Location change even when phone is kept on the table

When getting location from the android location manager, I face an issue. Even when I am sitting at a place and not moving, the latitude and longitude I get in onLocationChange() listener are always changing. I have set the update time 500ms and update distance as 5 meters. Any idea on how to fix it?
The GPS offset is arround 8 meters for normal phones and about 15-20 meters for old ones. You can set the minimum distance for more than 15 meters and it should help.
In case you are using NETWORK provider, than it takes it's locations from WiFi routers and Cellolar towers. in that case, if the phone changes a cell tower or pick up a new WiFi, than the location might change by more than then 20 meters (20-70 meters for WiFi and 500-1500 meters for cell towers).
Another thing you can do is to take into account the accuracy parameter of the locations you are getting, it should give you a rough estimate on the provider error (E.G. GPS vs Network vs WiFi) and you can try to understand if the phone is moving or not by calculating:
if (position_A.distanceTo(position_B) - position_B.getAcuracy() >0){
do something. //location change.
}
Update
see that for clarification, while the blue dot is the location your device gives you, the actual location can be anywhere in the blue radius.

Does Location#distanceTo(Location) take Location#getAccuracy() into account?

I want to write a LocationListener that takes the most accurate and precise recent location as its location. I'm intending to use this code in my LocationListener:
#Override
public void onLocationChanged(Location location) {
if(location.distanceTo(mLocation)>location.getAccuracy()){
mLocation = location;
}
}
What I intend this to do is update the location if the user's old location is outside the circle of "possible locations" that the new location indicates. So, for example, if our last measurement was a GPS signal and the new one is a cell tower, and the old location was in range of the cell tower, we don't update; on the other hand, if the cell tower is sufficiently distant, we know the user has moved and record that.
However, the distanceTo(Location) function states it returns the approximate distance in metres between locations. Does it already take the accuracy into account? Will it give me a precise enough figure to let me use in this way?
Short answer is no, Location.distanceTo(Location) does not take Location.getAccuracy() value into account when measuring distance.
Here's the actual code from the Android platform that is used to calculate distance for Location.distanceTo(Location):
https://github.com/android/platform_frameworks_base/blob/master/location/java/android/location/Location.java#L272
It uses Vincenty's Inverse Formula (http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf - Section 4) based on the given latitude and longitude (accuracy not considered).
As to whether your method of updating the "true" user location will be "precise enough", it really depends on GPS sensitivity, accuracy, and precision, which can vary significantly from device to device.
The accuracy estimate value from Location.getAccuracy() can also vary widely depending on the OEM, and typically devices I've seen overestimate accuracy (i.e., the device gives an accuracy value greater than the true accuracy) more than underestimate accuracy.
You might want to check out an app I created "GPS Benchmark" (http://www.gpsbenchmark.com/) which helps quickly benchmark location provider accuracy (GPS and Network) on Android devices, as well as "estimated accuracy" accuracy. I also co-authored a paper on this topic (http://journals.cambridge.org/repo_A82eaJIy) based on GPS benchmarking results from some Java ME devices, and most of the material is also relevant to Android.

Getting wrong location in LocationManager

I get totally wrong location when using the LocationManager with the Network provider. I get a Location out in the sea outside Africa, the accuracy is around 2000. My Google Maps is showing the accurate position.
Does anyone have a idea about what the problem can be? It is the same when I use the getLastKnownLocation().
The network location provider is extremely inaccurate. Usually if you are connected to WiFi, you can get within 100 meters, but on cell towers, 2000 meters is pretty normal. There's not really a problem, persay.
If Google Maps is able to get an accurate location with GPS turned off, then it is likely due to some very advanced location management that they do. But 2000 meters with Network Location, unfortunately, is normal in all of my test cases.
EDIT:
It is to say that the value of location.getAccuracy() is around 2000 (not a value in meters).
When getAccuracy() returns a value of 2000, it means meters. Here's what The Docs say about getAccuracy():
Returns the accuracy of the fix in meters. If hasAccuracy() is false, 0.0 is returned.
But it returns a float value, and while it doesn't display the unit, it is still meters.

Categories

Resources