开发者

Calculate real time distance traveled using google maps

开发者 https://www.devze.com 2023-02-18 14:49 出处:网络
There is a requirement to find the real time distance traveled using google maps. This should be calculated by the phone app itself. When I mean real time, I mean for example if the user is traveling

There is a requirement to find the real time distance traveled using google maps. This should be calculated by the phone app itself. When I mean real time, I mean for example if the user is traveling to point A, the user开发者_StackOverflow社区 can get to the point in many ways, what I want to do is calculate the total distance the user has traveled real time and not just assume and calculate the distance between the two points (which would not give the correct answer).

I googled around for this problem but could not find any method in doing so.

I personally thought of storing the longitude and latitude on the phone in a list and after the user reaches the destination the distance is caluclated using these points. However this means that I have to decide the interval in which these points are stored (every 1 min or so), which would mean that I would place location points in the list even though the user was actually still on the same road, which is quite unnecessary. Unless if anyone knows how to store the points at the appropriate time or some other solution

I am well more or less stumped on this problem, any help is really appreciated

The mobile platform is Android

Thanks, MilindaD


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

This is how gps tracking apps work.

Hope this helps ;)


I did it once and it is fairly simple. Use a service with a LocationListener. On every onLocationChanged() save the current Location, At the end you can calculate with Location.distanceBetween() all distances between these saved Locations.

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


you could try takeing the start point (IIRC their Long and Lat) then the end point and working out the euclidean distance between the two (see http://en.wikipedia.org/wiki/Euclidean_distance ).

I guess you what a better reloution then two point throgh, so take a third (or more) reading and work out A->B then add B->C.

Repeat for the resaloution you need.

to get the time of the journey. start a clock and stop it at the end (again you could take intermittent points if you wanted)

0

精彩评论

暂无评论...
验证码 换一张
取 消