Fetch accurate intermediate Location points in background and calculate Distance of Starting and ending locations in Android
Asked Answered
U

3

8

There may be similar questions regarding this topic,But I need your thoughts and suggestions on some specific requirement.

Here is my need - We are developing one app which tracks User's trip. The app will start collecting the location of that user in background,When user 'Starts' his trip from App.Background Service will be fetching locations on the basis of user's movement in specific time duration. When User 'Stops' his trip from App,We are calculating distance traveled by user with help of all recorded locations(With Google Distance calculating API). The App works fine in ideal case. But main challenge is - In some scenarios,We are not able to fetch exact and precise location of User. Scenarios affecting is - No internet,Data plan with 2g/3g,some specific areas where GPS is not returning accurate data etc.

Incorrect data of lat-long causes incorrect Trip distance and route.Which is main problem with the App.

Please,any one can suggest the best alternative/Suggestion for this? P.S. - We have tried GPS,Network,FusedLocationProvider.

EDIT 2 --

We have implemented logic on basis of accuracy and distances.Got nearer points. And just came across one useful api from Google that corrects some location points which are distracted from actual Roads. Posting here for reference of others...

Snap to Roads Api from Google

Unlearn answered 23/8, 2017 at 11:27 Comment(0)
G
2

this is a complicated topic.

One consideration you have to take. Android Oreo limits background services and that what you want to achieve won't work.

I would do is this (and it is the recommendation from Google)

When someone starts the trip (the user is aware of it), you must launch a on going notification with a foreground service , don't rely on background services anymore. Check the feature "Start Activity" in Google Fit App.

As for not having signal, or accurate GPS, well... it is a geographical problem!, there is nothing you could do. Or, maybe you can, using the LocationProvider.

FusedLocationProvider is fused within every app that requests locations updates.

Read this out, and see if that helps you.

https://developer.android.com/guide/topics/location/strategies.html

Gillyflower answered 31/8, 2017 at 19:14 Comment(6)
Foreground Services are not so appropriate in my App's requirement.. :( And I have reviewed working of Google fit.Besides Foreground service, I am more interested in locations tracked by them. They may be using sensors. correct?Unlearn
Also look at this github.com/googlesamples/android-play-location, check the sample "LocationUpdatesForegroundService", this could be a nice way to implement your app, the service starts in background, and when the app goes background, the service promotes itself to foreground and so on. It is very interesting.Gillyflower
Hey...We made conditions and logic with accuracy and distance to get nearer location points.Now the only issue is,when we get location on the other side of road,The distance is reflected.Any idea to get exact point on road only??During entire route??Unlearn
Use a function to calculate the distance between each point, if it is greater than 4,5,6, meters or the distance you want, just discard that point.Gillyflower
Thanks for feedback..But I came across one API that is useful in this case.Posting here for reference of others -- developers.google.com/maps/documentation/roads/snapUnlearn
thank you Aditi. That is great. Didn't know about that API.Gillyflower
C
1

Try to mix GPS and Accelerometer

If you detect that GPS stopped working, turn on accelerometer. If GPS is turned on again, calculate distance again with it. This way you can have route with GPS parts and accelerometer ones. The bigger GPS parts, the more accurate data will be

Carolinian answered 28/8, 2017 at 10:59 Comment(2)
Can you please provide any code snippet ? Example for the same?Unlearn
developer.android.com/guide/topics/sensors/… There is code about counting steps or you can listen for steps. #6368786 Here you can detect if GPS is turned off. When GPS is turned off, just start counting steps using accelerometer. When GPS is back on, stop counting steps with acceletometerCarolinian
H
1

How to get more accuracy by GPS_PROVIDER

Basically if the accuracy of a location isn't acceptable throw it away. The next one will be better.

Hoogh answered 31/8, 2017 at 21:56 Comment(5)
I have already tried this . But the problem is each device have different accuracy level to be considered as "BETTER" . For example,If I compare it with let's say 50 meters accuracy,Some Devices locations are not recorded as it has accuracy level always beyond that level.Some devices have min of 1500 - 2500 accuracy based on Hardware...Unlearn
Yes every device is different I wait for the 100 or less to come in on accuracy and create beautiful kml lines on the map. 2nd point accuracy is in meters 1500 is 1.5 clicks that's cell tower location not a GPS.Hoogh
Hey...We made conditions and logic with accuracy and distance to get nearer location points.Now the only issue is,when we get location on the other side of road,The distance is reflected.Any idea to get exact point on road only??During entire route??Unlearn
It happens some bad points on both sides. Two points 1. what if some road points are incorrect and the GPS point you received was spot on. 2. W e've all been in a car with GPS that didn't work as expected. "Turn Right" and there's nothing there.Hoogh
Thanks for feedback..But I came across one API that is useful in this case.Posting here for reference of others -- developers.google.com/maps/documentation/roads/snapUnlearn

© 2022 - 2024 — McMap. All rights reserved.