【问题标题】:Calculate distance by road using a series of points使用一系列点计算道路距离
【发布时间】:2016-03-28 06:04:30
【问题描述】:

我正在开发一个 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:

【问题讨论】:

  • 您可以使用航路点以及起点和终点,或者您可以使用“距离 = 速度 * 时间”来计算总距离。您必须找到记录的每 2 个点的平均速度,并将其乘以所用时间
  • @NakulSudhakar “您可以使用一些航路点以及起点和终点”您能告诉我怎么做吗?
  • @NakulSudhakar 感谢您的链接,我浏览了它。但它再次要求起点和终点,然后根据“谷歌推荐的”路线计算距离。我需要找到我的特定路线的距离,这可能与谷歌的建议不同。
  • 您可以指定起点和终点之间的航点。这样你的实际路径将与谷歌建议的非常相似。

标签: android google-maps geolocation google-distancematrix-api


【解决方案1】:

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

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

默认情况下,路线服务按给定顺序计算通过提供的航点的路线。或者,您可以将 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[],您可以获得两个航点之间的具体距离。通过添加所有这些,您将获得总距离。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 2023-01-26
    • 2011-01-12
    相关资源
    最近更新 更多