如何在地图上仅在半径(圆形)内显示标记? [英] How to show markers only inside of radius (circle) on maps?
本文介绍了如何在地图上仅在半径(圆形)内显示标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有标记都基于firebase的数据纬度和经度显示在地图上.我只想在地图上的圆圈内显示标记,距当前位置的圆圈半径为10公里.
All of markers shows up on maps based from data latitude and longitude from firebase. And i want to show markers on maps only inside of the circle, circle radius from current place is 10 kilometers.
这是我显示Firebase中所有标记的方式
This is how i show all markers from Firebase
LatLng newlocation = new LatLng(dataSnapshot.child("latitude").getValue(Double.class),dataSnapshot.child("longitude").getValue(Double.class));
nama = new String(dataSnapshot.child("nama").getValue(String.class));
googleMap.addMarker(new MarkerOptions().position(newlocation).title(nama+"")));
这是我如何在当前位置周围显示一个圆圈:
This is how i show a circle around current place location :
LatLng latLng = new LatLng(latitude, longitude);
mMap.addCircle(new CircleOptions()
.center(latLng)
.radius(10000)
.strokeWidth(0f)
.fillColor(0x550000FF));
请问我更多细节!
推荐答案
使用此公式查找两个纬度和经度之间的距离,此函数将返回以米为单位的距离
Use this formula to find distance between two latitude and longitude this function will return distance in meter
double getDistance(double LAT1, double LONG1, double LAT2, double LONG2) {
double distance = 2 * 6371000 * Math.asin(Math.sqrt(Math.pow((Math.sin((LAT2 * (3.14159 / 180) - LAT1 * (3.14159 / 180)) / 2)), 2) + Math.cos(LAT2 * (3.14159 / 180)) * Math.cos(LAT1 * (3.14159 / 180)) * Math.sin(Math.pow(((LONG2 * (3.14159 / 180) - LONG1 * (3.14159 / 180)) / 2), 2))));
return distance;
}
您可以轻松实现与问题相关的逻辑部分
you can implement the logical part associated with your problem easily
这篇关于如何在地图上仅在半径(圆形)内显示标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文