Calculate distance in real time using Google Maps

There is a requirement to find the real-time distance covered by Google maps. This should be calculated by the phone itself. When I mean real time, I mean, for example, if a user travels to point A, the user can get to the point in different ways, I want to calculate the total distance that the user traveled in real time, and not just assume and calculate the distance between two points (which will not give the correct answer).

I was looking for this problem but could not find any method.

I personally thought about saving the longitude and latitude on the phone in the list, and after the user reaches the destination, the distance will be highlighted using these points. However, this means that I must determine the interval in which these points are stored (every 1 min or so), which would mean that I would place the location points in the list, even if the user was actually still at the same a path that is completely unnecessary. If only someone knows how to save points at the right time or some other solution

I am more or less focused on this issue, any help is really appreciated

Mobile Platform - Android

Thanks, MilindaD

+4
source share
3 answers

I think the best solution is to save the position every X seconds, and then calculate the total distance between them, and to get the time you just need to see the difference between the last point and the first.

Here's how gps tracking apps work.

Hope this helps;)

+1
source

you can try to take the start point (IIRC their long and lat), then the end point and work out the Euclidean distance between them (see http://en.wikipedia.org/wiki/Euclidean_distance ).

I assume you have a better switch, then two points, so do a third (or more) reading and generating A-> B, then add B-> C.

Please try again to retry.

to get travel time. start the clock and stop it at the end (again, if you want, you can take broken points)

0
source

I did it once, and it's pretty simple. Use the service using the LocationListener. On each onLocationChanged (), we save the current location. In the end, you can calculate with Location.distanceBetween () all the distances between these saved locations.

Please keep in mind that it becomes more accurate with faster tracking. For walks, you need fewer updates than driving a car. This can be set using minDistance and / or minTime in LocationManager.requestLocationUpdates ().

0
source

Source: https://habr.com/ru/post/1344622/


All Articles