通过标记Google Maps API(Android)查找标记

And*_*Lam 1 android google-maps google-maps-api-3

如何/在哪里可以获得地图上当前所有标记对象的引用,以便检查以下内容:

if (Markers.getTag().equals("something"))
Run Code Online (Sandbox Code Playgroud)

通过阅读Marker上的文档,它说"这比存储单独的Map更容易",所以我不想使用HashMap,除非有人说我绝对必须这样做.

谢谢,以下是伪伪代码

// uid是Marker的标签

// 1)在某种程度上检查当前配置文件是否存在标签

// 2)如果存在,则只需移动标记,只需设置此标记的新位置即可.

// 3)如果没有,则创建一个新标记,添加标记.

// 4)通过.setTag()将配置文件uid设置为标记的标记

// 5)动画移动相机到latlng位置

3-5是可以的,只需1-2

// 3) Create a new marker
                            // Marker to show on the map
                            Marker friendMarker;

                            // Add a marker when the image is loaded
                            friendMarker = googleMap.addMarker(new MarkerOptions()
                                            .position(friendLatLng)
                                            .icon(BitmapDescriptorFactory.fromBitmap(bitmap))
                                            .title(friendProfile.getName()));

                            // Set the tag on this friend marker, so we can retrieve or update it later
                            friendMarker.setTag(friendProfile.getUid());

                            // 5) Animate the camera to that location
                            CameraPosition cameraPosition = new CameraPosition.Builder().target(friendLatLng).zoom(15).build();
                            googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
Run Code Online (Sandbox Code Playgroud)

mar*_*awa 6

创建标记列表

List<Marker> markers = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)

然后在制作商列表中添加您的标记

// Marker to show on the map
Marker friendMarker;

// Add a marker when the image is loaded
friendMarker = googleMap.addMarker(new MarkerOptions()
               .position(friendLatLng)                     
               .icon(BitmapDescriptorFactory.fromBitmap(bitmap))
               .title(friendProfile.getName()));

//Add now the marker in markers list
markers.add(friendMarker);
Run Code Online (Sandbox Code Playgroud)

然后访问所有标记

for (Marker marker : markers) {
     if (marker.getTag().equals("something")) { //if a marker has desired tag
         //Do something in the way. Hmmmm. Yeah
     }
}
Run Code Online (Sandbox Code Playgroud)