【发布时间】:2016-09-20 08:26:47
【问题描述】:
我想通过给出标题来关注标记我现在通过使用 lat 和 lng 来关注
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.89454, 75.82607), 15.0f));
所以无论如何我可以通过标记的标题名称关注特定标记
【问题讨论】:
标签: android google-maps
我想通过给出标题来关注标记我现在通过使用 lat 和 lng 来关注
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.89454, 75.82607), 15.0f));
所以无论如何我可以通过标记的标题名称关注特定标记
【问题讨论】:
标签: android google-maps
您可以将标记存储在Map<String Marker> 中,使用标题作为键:
private Map<String, Marker> markers = new HashMap<>();
当您将标记添加到地图时,您还需要将它们添加到哈希图中:
String markerTitle = "My Marker";
LatLng markerPosition = new LatLng(26.89454, 75.82607);
Marker marker = mMap.addMarker(new MarkerOptions().position(markerPosition).title(markerTitle));
markers.put(markerTitle, marker); // Add the marker to the hashmap using it's title as the key
然后您可以将查询哈希图的标记居中:
private void centerMarker(String title) {
Marker marker = markers.get(title);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(), 15f));
}
【讨论】: