简体   繁体   English

Android Java 谷歌地图 api v2 :: 如何检查标记在谷歌地图上的圆圈内 android api v2

[英]Android Java google maps api v2:: how check with markers are within a circle on google maps android api v2

How to check if markers are present within radius of circle and how to enable only those marker which are present under the area of circle?如何检查圆半径内是否存在标记以及如何仅启用圆区域下存在的那些标记?

I used circle option to create circle on map on click of marker.我使用圆选项在点击标记时在地图上创建圆。 I just want only those markers visible which are inside the circle.我只想要圆圈内的那些标记可见。

$$mMap.setOnMarkerClickListener(new OnMarkerClickListener() {
    @Override
    public boolean onMarkerClick(Marker marker) {
        CircleOptions circle = new CircleOptions();
        circle.center(latLng).fillColor(Color.LTGRAY).radius(1000);
        mMap.addCircle(circle);
        // circle.`enter code here`
        return true;
    }
});

It should be pretty easy.这应该很容易。 Your circle has a latlng point and radius value.你的圆有一个纬度点和半径值。 Calculate distance of each point from the circle center.计算每个点到圆心的距离。 Whose distance is less than the radius, they are in your circle and remaining are not.谁的距离小于半径,他们在你的圈子里,剩下的不在你的圈子里。 Here is the code to find distance between two latlngs.这是查找两个纬度之间距离的代码。

private double distance(double lat1, double lon1, double lat2, double lon2) {
      double theta = lon1 - lon2;
      double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
      dist = Math.acos(dist);
      dist = rad2deg(dist);
      dist = dist * 60 * 1.1515;
       return (dist);
    }

   private double deg2rad(double deg) {
      return (deg * Math.PI / 180.0);
    }
   private double rad2deg(double rad) {
      return (rad * 180.0 / Math.PI);
    }

You should have list of latlngs that you used earlier to add markers to map.您应该拥有之前用于向地图添加标记的 latlng 列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM