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.
Related
I'm getting current location in my app by LocationServices API FusedLocationApi. Which gets location from gps, wifi and cell towers. When drawing route by geopoints I find very strange behavior in one place. Staying in this place I get points and one of them have coordinates near me and another have coordinates of a place which is more than 0.5 kilometers from me. And all points that are far from me lies in place which radius is 3-5 meters. The accuracy I get from Location method getAccuracy() is rather high.
The only reason of it I see in long range wifi. The only solution I find yet is to disable sending points of the place which radius is 3-5 meters to my server. Does anybody knows how can I identify this wifi point and ban it. I thought maybe Location method getProvider() give me some data but it allways writes "fused"))
Hi i am working on a real time location tracking application where i have used Fused Location provider Api. I was able to get the location updates when the device is moving. But i was also able to get the location updates even if the device is stationary on a table when i am indoor. So I have calculated the distance between the last location and the current location triggered in Onlocationchanged event and checked whether the distance is less than 30 metres, to know the device is actually moving. But sometimes the distance i get is greater than 400 metres (indoor/Device is Stationary). How Can i ignore the onlocationchange event when i am indoor? Any suggestions are appreciated.Thanks in advance.
Unfortunately I don't believe there's much you can do about it.
The reason you see those updates with great changes it's because indoors, you won't get a GPS lock, so the device is relying on cell tower and WiFi hotspot triangulation to determine your location, and something around 200m to 1km is the best you'll get with this kind of technology.
A possible attempt to hack-around it would be to:
check the source and precision of the location update
use the activity recognition API to guess if the device really moved
but both are a hack, around the technology limitation and might not be as reliable.
I've got an app which sets up two location listeners (one for GPS and one for network) and then chooses the location from the best one available, which should be GPS. However, if GPS is turned on, it will always choose the GPS location, even if the person starts the app up indoors. This has led to the GPS location being used even if the last known GPS location is from miles away and the network location is actually much more accurate.
Is there any way around this issue or is it just something that will need to be accepted as an issue with using GPS & network? Is the standard practice just to assume that GPS is always more accurate even though it's possible that it might not be in certain instances?
If you are using the network provider to fetch the location they are not very accurate when compared to GPS. So it can be a good idea to fetch the accuracy of your position using network provider when you are indoors as GPS doesnt function well indoors and you can use GPS to get the location updates when you are outdoor.
You can use GetAccuracy() method of Location class and see for the value it returns. Let Say if getAccuracy() retruns 25 then you can leave this value wait for another gps value until you get the desired value. Remember the value it returns is the radius of the circle in meters.
I implemented the new LocationClient into my app, but doing a test run I noticed the readings are incorrect.
I was driving outside without GPS. WLAN on. Thus location accuracy can only be what used to be NETWORK.
I set the LocationClient to LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY; and update interval to 15 sec.
When I get the data I evaluate the Location with getAccuracy() and getTime(). Both values can not be trusted.
I get an accuracy of 25 to 50m, sometimes up to 100 meters, typical for WIFI locations. However, once I left home, the location reported (with getAccuray() < 100) had nothing much to do with my current location (actual accuracy >800m). It resembled best the cell tower location. Location was never updated in the hour I was traveling, thus always pointing to the same cell tower (incidently I always was in that area although traveling about 3 km).
Doing further tests I noticed that location and accuracy did not change for at least a minute after I turned wifi off. I was walking, so accelerator should be triggered. Again, location was way off to where I was, but accuracy still reported < 30m. After about 1-2 Minutes, the location was then reported with accuracy >800 m which was correct.
I can live with bad accuracy, but I need to know that.
Time is always updated to latest time also while the actual reading is older. This also seems a bug, someone already raised an issue at google for that.
Summarized it means I can not use that functionality. I get old readings reported as current and accuracy which does not match the reading.
Test where done on a Nexus 4. Phone was connected to an UMTS (3G) cell.
Are these known issues? Is there a way to work around it (getting the correct accuracy), or do I have to use the "old" 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.