I am developing an Android application. I need to find the distance between two geo coordinates.
I used Location.distanceBetween()
and Location.distanceTo()
functions. These functions give the straight distance, but the actual distance is different when we travel by road.
I want the distance between two geo points when the user travels by road. Does anyone know how to do this?
Use Directions API to get a "route" from GeoPoint X to GeoPoint Y. You'll get a list of points, that represent lines (legs, or segments) that you'll need to take to reach Y from X.
You can measure the distances between the points but DO NOT DO THAT because the XML or JSON result will contain the total distance of the route. You can use the information about each line to draw a polyline on the map.
There doesn't seem to be an Android API, only an API that returns XML or JSON that you'll need to parse. Like what is done here: Google Maps Directions - Which API?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With