Android-仅在地图中显示确定区域中包含的标记

Jay*_*Jay 4 java maps android google-maps coordinates

我的应用程序带有地图。在此地图中,我在设备的当前位置放置了一个标记。我还围绕标记添加了一个圆圈,如下所示:

    Circle circle = mMap.addCircle(new CircleOptions()
                        .center(latLng)
                        .radius(400)     //The radius of the circle, specified in meters. It should be zero or greater.
                        .strokeColor(Color.rgb(0, 136, 255))
                        .fillColor(Color.argb(20, 0, 136, 255)));
Run Code Online (Sandbox Code Playgroud)

结果是这样的:
这是结果的示例

我有一个数据库,其中某些位置的特征是经度和纬度。

我将在地图中设置标记,仅针对先前添加的圆内的位置。
我如何理解该区域中包括哪些?

请帮助我,谢谢!

ant*_*nio 5

您可以添加所有标记,首先使其不可见,然后计算圆心与标记之间的距离,以使给定距离内的标记可见:

private List<Marker> markers = new ArrayList<>();

// ...

private void drawMap(LatLng latLng, List<LatLng> positions) {
    for (LatLng position : positions) {
        Marker marker = mMap.addMarker(
                new MarkerOptions()
                        .position(position)
                        .visible(false)); // Invisible for now
        markers.add(marker);
    }

    //Draw your circle
    Circle circle = mMap.addCircle(new CircleOptions()
            .center(latLng)
            .radius(400)
            .strokeColor(Color.rgb(0, 136, 255))
            .fillColor(Color.argb(20, 0, 136, 255)));

    for (Marker marker : markers) {
        if (SphericalUtil.computeDistanceBetween(latLng, marker.getPosition()) < 400) {
            marker.setVisible(true);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

请注意,我使用的SphericalUtil.computeDistanceBetweenGoogle Maps API实用程序库中的方法


Yas*_*maz 0

您可以看一下这个问题,了解如何计算两个纬度经度之间的距离:how-to-calculate-distance- Between-two-locations-using-their-longitude-and-latitu

\n\n

\xc4\xb0f 2 点之间的距离小于你的圆的半径(对于你来说 400)为它们放置标记。(也不要只看选定的答案。selected_location.distanceTo(another_location)下面的答案将会帮助你。)

\n