[英]How to calculate distance between two markers within ArrayList?
so i have randomly generated 5 markers all within an ArrayList however i would to calculate the distance between the markers and only display the markers that are within 500 meters from each other, may code so far: 因此,我在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);
}
the code above successfully creates 5 markers placed randomly around a given radius, however i would only like to display the markers that are within 500 meters from each other, i get a guaranteed of 3 markers that are 500 meters apart but how can i show only 2 of them? 上面的代码成功创建了5个沿给定半径随机放置的标记,但是我只想显示彼此相距500米以内的标记,我保证3个距离相隔500米的标记,但是如何只显示他们两个?
You can use the Google Maps Android API utility library that has a function to calculate distance between two LatLng: 您可以使用Google Maps Android API实用程序库,该库具有计算两个LatLng之间的距离的功能:
http://googlemaps.github.io/android-maps-utils/ http://googlemaps.github.io/android-maps-utils/
The computeDistanceBetween() from SphericalUtil is the function you should use in your code. SphericalUtil中的computeDistanceBetween()是您应该在代码中使用的函数。
Please read the following documentation for further details 请阅读以下文档以获取更多详细信息
https://developers.google.com/maps/documentation/android-api/utility/#spherical https://developers.google.com/maps/documentation/android-api/utility/#spherical
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.