How To Focus At Marker In Google Map In Android
I just want to know whether we can focus at added marker in android application or not. If yes, how? or is there any alternative way to get this task done. lets say I have added a
Solution 1:
You have to calculate of all the markers. To do so
LatLngBounds.Builderbuilder=newLatLngBounds.Builder();
foreach(Marker m : markers) {
builder.include(m.getPosition());
}
LatLngBoundsbounds= builder.build();
Now obtain CameraUpdateFactory
:
intpadding=0; // offset from edges of the map in pixelsCameraUpdatecu= CameraUpdateFactory.newLatLngBounds(bounds, padding);
Finally move camera on group of markers like this :
googleMap.moveCamera(cu);
Or if you want an animation:
googleMap.animateCamera(cu);
Solution 2:
You can do something like this. What you have to do is to iterate trough your markers and find the outer most coordinates.
LatLngBoundsbounds=newLatLngBounds(southWest, northEast);
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, MAP_PADDING));
Post a Comment for "How To Focus At Marker In Google Map In Android"