How do I focus a Google marker on a marker title?

I want to focus on the marker, giving the name right now, I focus with lat and lng

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.89454, 75.82607), 15.0f)); 

So, anyway, I could focus on a specific marker by the name of the marker name

+6
source share
1 answer

You can save your markers in Map<String Marker> , using the title as a key:

 private Map<String, Marker> markers = new HashMap<>(); 

When you add markers to the map, you also need to 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 title as the key 

Then you can center the marker by requesting a hash map:

 private void centerMarker(String title) { Marker marker = markers.get(title); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(), 15f)); } 
+5
source

All Articles