0

我正在開發一個android應用程序,其中我每5分鐘記錄一次設備的點數。現在我想用這些點來計算道路所覆蓋的總距離。有沒有辦法做到這一點。在google apis中,我看到有一個起點和終點使用它計算距離,但可能有多條路線相同。我需要找到這條特定路線的距離。我怎麼做?使用一系列點計算道路距離

感謝

編輯:

在谷歌距離矩陣API已經有多個起點和多個目的地的選項。我不知道如果這是任何幫助:

origins — One or more locations to use as the starting point for calculating travel distance and time. 
You can supply one or more locations separated by the pipe (|) character, in the form of an address or latitude/longitude coordinates. If you pass an address as a string, the service will geocode the string and convert it to a latitude/longitude coordinate to calculate distances. If you pass coordinates, ensure that no space exists between the latitude and longitude values. 
origins=Bobcaygeon+ON|41.43206,-81.38992 
Alternatively, you can supply an encoded set of coordinates using the Encoded Polyline Algorithm. This is particularly useful if you have a large number of origin points, because the URL is significantly shorter when using an encoded polyline. Encoded polylines must be prefixed with enc: and followed by a colon (:). For example: origins=enc:gfo}EtohhU: 
destinations — One or more locations to use as the finishing point for calculating travel distance and time. 
You can supply one or more locations separated by the pipe (|) character, in the form of an address or latitude/longitude coordinates. If you pass an address as a string, the service will geocode the string and convert it to a latitude/longitude coordinate to calculate distances. If you pass coordinates, ensure that no space exists between the latitude and longitude values. 
destinations=Darling+Harbour+NSW+Australia|24+Sussex+Drive+Ottawa+ON|Capitola+CA 
Alternatively, you can supply an encoded set of coordinates using the Encoded Polyline Algorithm. This is particularly useful if you have a large number of destination points, because the URL is significantly shorter when using an encoded polyline. Encoded polylines must be prefixed with enc: and followed by a colon (:). For example: destinations=enc:gfo}EtohhU: 
+0

您可以使用這些路標以及起點和終點,也可以使用「距離=速度*時間」來計算總距離。你必須找到你記錄的每個2分的平均速度,並乘以時間乘以 –

+0

@NakulSudhakar「你可以使用這些路標,以及起點和終點」你能告訴我怎麼做嗎? –

+0

http://wptrafficanalyzer.in/blog/driving-distance-and-travel-time-duration-between-two-locations-in-google-map-android-api-v2/ http://wptrafficanalyzer.in/blog/route-between-two-locations-with-way-in-google-map-android-api-v2/ 請看看這個。 –

回答

1

我認爲你可以使用的Google Maps Direction API的航點,以表明你要計算的具體道路/點。

您可以地址,緯度/經度座標或地點ID的形式提供由管道字符(|)分隔的一個或多個waypoints位置。

默認情況下,路線服務會按照給定的順序計算通過提供的航點的路線。或者,您可以在waypoints參數中傳遞optimize:true作爲第一個參數,以允許Directions服務通過以更有效的順序重新排列航點來優化提供的路線。

當Google Maps Directions API返回結果時,它將它們放入(JSON)路由數組中。 routes數組的每個元素都包含來自指定原點和目的地的單個結果。這條路線可能由一條或多條路線組成,具體取決於是否指定了任何路標。

另一種方法是使用legs[]字段中的步驟[]。

routes字段中的每個路由都包含了leg []。

legs[] - 包含一個數組,其中包含關於給定路線內兩個位置之間的路線腿的信息。對於指定的每個航點或目的地,將出現單獨的支線。

每個腿字段(一個或多個)可以包含像

  • distance下列字段指示由該腿所覆蓋的總距離,作爲一個字段包含下列元素
  • steps[]包含的步驟表示信息的數組關於行程的每個單獨步驟

steps數組中的每個元素都定義了計算方向的單個步驟。一個步驟是方向路線中最原子的單位,包含描述旅程中特定單一指令的單個步驟。例如。 「在W. 4th St.左轉」該步驟不僅描述指令,而且還包含與本步驟如何與後續步驟相關的距離和持續時間信息。例如,表示爲「合併到I-80 West」的步驟可以包含「37英里」和「40分鐘」的持續時間,表示下一步距此步驟37英里/ 40分鐘。

通過使用steps[]您可以獲得兩個航點之間的特定距離。通過添加所有這些,您將獲得總距離。