【问题标题】:How to calculate distance between two markers within ArrayList?如何计算ArrayList中两个标记之间的距离?
【发布时间】:2017-04-15 15:44:22
【问题描述】:

所以我在一个 ArrayList 中随机生成了 5 个标记,但是我会计算标记之间的距离,并且只显示彼此相距 500 米以内的标记,到目前为止可能会编码:

ArrayList<Marker> ArrM = new ArrayList<Marker>();

    for (int i = 0; i < 5; i++){
Marker marker = mMap.addMarker(
                new MarkerOptions()
                        .position(computeOffset(mLatLng,ranDist,newRandomHeading))
                        .visible(true)
                        .title("Marker"));
       ArrM.add(marker);
    }

上面的代码成功地创建了 5 个随机放置在给定半径周围的标记,但是我只想显示彼此相距 500 米范围内的标记,我保证有 3 个相距 500 米的标记,但是怎么能我只显示其中 2 个?

【问题讨论】:

  • 从我在文档中看到的内容来看,这个 API 并不适合任何类型的计算。试试Google Maps Services API,它应该有你需要的一切。

标签: java android google-maps google-maps-android-api-2


【解决方案1】:

您可以使用具有计算两个 LatLng 之间距离的功能的 Google Maps Android API 实用程序库:

http://googlemaps.github.io/android-maps-utils/

来自 SphericalUtil 的 computeDistanceBetween() 是您应该在代码中使用的函数。

请阅读以下文档了解更多详情

https://developers.google.com/maps/documentation/android-api/utility/#spherical

希望对您有所帮助!

【讨论】:

    猜你喜欢
    • 2016-03-25
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    • 2020-02-12
    • 2018-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多