簡體   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