【问题标题】:How to calculate LatLng A to LatLng B on existing polyline?如何在现有折线上计算 LatLng A 到 LatLng B?
【发布时间】:2021-01-20 01:02:43
【问题描述】:

我正在开发一款类似于 Waze 或 Google Maps 的 Android 应用。我已经有一个由 Direction API 填充的折线

现在我需要根据生成的折线计算从标记 A 到标记 B 的距离

我假设我可以通过循环折线坐标来计算距离,但标记位于折线坐标的中间。可以看到底部的距离,即标记 A 和标记 B 之间的直线距离,这是不正确的。

有谁知道如何根据生成的折线计算标记 A 到标记 B 之间的距离?

任何帮助都会很棒!谢谢!有什么问题请追问

【问题讨论】:

  • @AndriiOmelchenko 你指的是 SphericalUtil.computeDistanceBetween() 函数?不。我不希望获得点 A 到点 B 之间的直线距离。就像我在问题中提到的那样,我想要基于方向/折线的点 A 到点 B 之间的距离

标签: android google-maps kotlin marker polyline


【解决方案1】:

从生成从 Directions API 获取的折线的坐标列表中获取标记 A 坐标的索引以及标记 B 坐标的索引,然后循环,从标记 A 的索引开始并在市场 B. 使用下面的 gradle 代码下载 Google maps utils 库。

dependencies {

  // KTX for the Maps SDK for Android library
  implementation 'com.google.maps.android:maps-ktx:2.1.3'

  // KTX for the Maps SDK for Android Utility Library
  implementation 'com.google.maps.android:maps-utils-ktx:2.1.3'

  // It is recommended to also include the latest Maps SDK and/or Utility Library versions
  // as well to ensure that you have the latest features and bug fixes.
  implementation 'com.google.android.gms:play-services-maps:17.0.0'
  implementation 'com.google.maps.android:android-maps-utils:2.0.3'
}

然后您可以使用从上述库的 PolyUtil 类中获取的以下方法来获取标记点 A 和 B 的索引:

 Polyutil.locationIndexOnEdgeOrPath(LatLng point, java.util.List<LatLng> poly, boolean closed, boolean geodesic, double toleranceEarth)

使用以下选项:

  1. 关闭(假)
  2. 测地线(假)
  3. toleranceEarth (0.01)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-03
    • 2013-06-26
    • 2013-05-02
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    相关资源
    最近更新 更多