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[]您可以获得两个航点之间的特定距离。通过添加所有这些,您将获得总距离。