Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 472
Aditi Parikh Avatar asked Aug 23 '17 11:08

Aditi Parikh


2 Answers

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

like image 124
Pedro Varela Avatar answered Sep 27 '22 15:09

Pedro Varela


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

like image 35
Janusz Hain Avatar answered Sep 27 '22 15:09

Janusz Hain