Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find distance (by road) between 2 geo points in Android application?

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?

like image 737
katra Avatar asked Oct 05 '22 06:10

katra


1 Answers

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?

like image 168
Mzn Avatar answered Oct 13 '22 10:10

Mzn