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:
4

1 回答 1

1

我认为您可以使用Google Maps Direction API的航点来指示您要计算的特定道路/点。

您可以以地址、纬度/经度坐标或地点 ID 的形式提供一个或多个由竖线字符 (|) 分隔的航点位置。

默认情况下,Directions 服务会按照给定的顺序计算通过提供的航点的路线。或者,您可以将 optimize:true 作为航点参数中的第一个参数传递,以允许方向服务通过以更有效的顺序重新排列航点来优化提供的路线。

当 Google Maps Directions API 返回结果时,它会将它们放在 (JSON) 路线数组中。routes 数组的每个元素都包含来自指定起点和终点的单个结果。根据是否指定了任何航路点,这条路线可能包含一条或多条航路。

另一种方法是使用legs[]字段中的steps[]。

routes 字段中的每条路线都包含legs[]。

legs[]- 包含一个数组,其中包含有关给定路线内两个位置之间的路线段的信息。每个指定的航路点或目的地都有一个单独的航段。

每个腿字段可能包含以下字段,例如

  • distance表示这条腿所覆盖的总距离,作为一个包含以下元素的字段
  • steps[]包含一系列步骤,表示有关旅程中每个单独步骤的信息

steps 数组中的每个元素都定义了计算方向的一个步骤。步骤是方向路线的最原子单位,包含描述旅程中特定的单个指令的单个步骤。例如“在 W. 4th St. 左转。” 该步骤不仅描述了指令,还包含与该步骤如何与下一个步骤相关的距离和持续时间信息。例如,表示为“Merge into I-80 West”的步骤可能包含“37 英里”和“40 分钟”的持续时间,表示下一步距离该步骤 37 英里/40 分钟。

通过使用,steps[]您可以获得两个航点之间的具体距离。通过添加所有这些,您将获得总距离。

于 2016-03-28T14:37:36.940 回答