【发布时间】:2017-10-01 21:01:33
【问题描述】:
我如何/在哪里可以获得地图上当前所有标记对象的参考,以便检查如下内容:
if (Markers.getTag().equals("something"))
通过阅读 Marker 上的文档,它说“这比存储单独的 Map 更容易”,所以我不想使用 HashMap,除非有人说我必须这样做。
谢谢,下面是伪伪代码
// uid是Marker的标签
// 1) 检查当前配置文件是否存在标签
// 2) 如果存在,则移动标记,设置此标记的新位置即可。
// 3) 如果没有,则创建一个新的标记,添加一个标记。
// 4) 通过 .setTag() 将 profile uid 设置为 Marker 的 Tag
// 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));
【问题讨论】:
标签: android google-maps google-maps-api-3