如何通过标记标题关注Google标记? [英] how to focus google marker by marker title?
本文介绍了如何通过标记标题关注Google标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过给予标题来关注标记,现在我正在使用lat和lng进行关注。
i want to focus on marker by giving title right now i am focusing by using lat and lng
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.89454, 75.82607), 15.0f));
因此,无论如何,我都可以通过标记的标题名称专注于特定标记。
So is there anyway i could focus on particular marker by Title name of the marker
推荐答案
您可以将标记存储在 Map< String Marker>
key:
You can store your markers in a Map<String Marker>
using the title as the key:
private Map<String, Marker> markers = new HashMap<>();
当您将标记添加到地图时,还需要将它们添加到散列贴图:
When you add your markers to the map, you need to also add them to the 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
然后您可以将标记查询居中HashMap:
Then you can center your marker querying the hashmap:
private void centerMarker(String title) {
Marker marker = markers.get(title);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(), 15f));
}
这篇关于如何通过标记标题关注Google标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文