繁体   English   中英

Android:如何计算两点之间的距离

[英]android: how to calculate distance between two points

我想计算两点之间的距离。 我用谷歌搜索,但是我发现的只是最短的路径距离,我不想知道两点之间的道路距离。

看来Google Directions API有所改变。

这是新的:

您可以使用google maps api获取路线

您可以在Json设置请求中的参数时将请求与响应一起使用。

http:// maps.google.com/maps/api/directions/ json ?origin = 40.484037,-3.673553&destination = 40.419508,-3.693466&sensor = false&units = metric

或作为XML

http:// maps.google.com/maps/api/directions/ xml ?origin = 40.484037,-3.673553&destination = 40.419508,-3.693466&sensor = false&units = metric

您可以设置起源命运值作为模式的起点和终点,你想,散步,骑自行车,驾驶...

然后以公制英制设置单位

在返回的JSON或XML上,您可以解析所需的信息。

您还可以像在MAPS API上的示例一样设置航路点。

在腿TAG上,第一距离将是两点之间的总距离。

 "legs" : [
            {
               "distance" : {
                  "text" : "11,7 km",
                  "value" : 11661
               },
               "duration" : {
                  "text" : "16 min",
                  "value" : 941
               },

您可以立即解析所有需要的信息:)

希望能帮助到你。

您可以使用http://maps.google.com/maps?saddr= {start_address}&daddr = {destination_address}

它将提供方向细节以及两个位置之间的距离和时间

http://maps.google.com/maps?saddr=79.7189,72.3414&daddr=66.45,74.6333&ie=UTF8&0&om=0&output=kml

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM