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
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
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));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With