Reputation: 864
How to find distance from polyline in google map in android using map apiV2 ? I want to find distance when user start moving from one location to another . I used the Calculate distance in meters when you know longitude and latitude in java but it takes distance between two lat-long not as per user moves in map. Please help me if anyone knows how to find distance using polyline.
Upvotes: 2
Views: 3396
Reputation: 552
For finding distance from your polyline you can use PolyUtil class which contains one method distanceToLine . implementation'com.google.maps.android:android-maps-utils:0.5+' add this library in your build.gradle. For more you can use Google map utility class
https://developers.google.com/maps/documentation/android-api/utility/
Upvotes: 3
Reputation: 9080
Based on the answer given by Gevaria Purva I found a more appropriate method on PolyUtil named isLocationOnPath.
For the third parameter most likely you want to pass true
.
Upvotes: 0
Reputation: 322
For this you need to use thread. In that at regular interval you should find the distance between current coordinates and last saved coordinate.
Raw code:
Coordinate current, last;
Distance D = 0;
while (true) {
wait(10000);
last = current;
current = getNewCordinate;
d = D + distFrom(current, last);
}
This logic will help.
Upvotes: 1