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

别来无恙 提交于 2019-12-07 06:32:14

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/16249693/how-to-find-distance-by-road-between-2-geo-points-in-android-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!