【问题标题】:Reveal markers around a selected location on Google Maps在 Google 地图上显示选定位置周围的标记
【发布时间】:2016-10-29 01:38:33
【问题描述】:

我目前正在为 Google 地图编写 Android Studio。

我使搜索功能根据搜索栏上搜索的文本工作。一旦用户按下“搜索”,地图就会放大到选定的位置并放置一个彩色标记。

但是,我想这样做:

一旦您选择了位置,您将根据某个半径/某个区域显示几个标记。

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    您可以将标记添加到地图中,使其不可见,并计算所需位置与每个标记之间的距离,以显示比给定距离更近的标记。

    private List<Marker> markers = new ArrayList<>(); // List to hold your markers
    

    将标记添加到地图和列表中:

    Marker marker = mMap.addMarker(new MarkerOptions().position(yourPosition).visible(false));
    markers.add(marker);
    

    然后创建一个函数,给定 LatLng 计算到每个标记的距离(我使用来自 Google Maps Android API Utility LibrarySphericalUtil.computeDistanceBetween)并显示所需的标记:

    private void showMarkers(LatLng location, float distance) {
        for(Marker marker : markers) {
            if (SphericalUtil.computeDistanceBetween(marker.getPosition(), location) <= distance) {
                marker.setVisible(true);
            } else {
                marker.setVisible(false);
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多