如何找到在Android应用地理2点之间的距离(公路)? [英] How to find distance (by road) between 2 geo points in Android application?

查看:239
本文介绍了如何找到在Android应用地理2点之间的距离(公路)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序。我需要找到两个地理坐标之间的距离。

I am developing an Android application. I need to find the distance between two geo coordinates.

我用 Location.distanceBetween() Location.distanceTo()功能。这些功能给的直线距离,但实际距离是不同的,当我们通过公路旅行。

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?

推荐答案

使用路线API 获得,你需要采取从十到Y以GeoPoint的Y.路线,从GeoPoint的X您会得到点的列表,即重新present线(腿,或段)

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.

您可以测量点,但之间的距离DO的的做,因为在XML或JSON结果的将会的包含路线的总距离。您可以使用每个行的信息,在地图上绘制折线。

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.

似乎没有成为一个Android API,只有返回XML或JSON,你需要解析的API。什么样的事情都是在这里完成:谷歌地图路线 - 哪些API

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?

这篇关于如何找到在Android应用地理2点之间的距离(公路)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆