How to Focus at Marker in google map in android

痴心易碎 提交于 2019-12-03 09:02:00

You have to calculate of all the markers. To do so

LatLngBounds.Builder builder = new LatLngBounds.Builder();
for each (Marker m : markers) {
    builder.include(m.getPosition());
}
LatLngBounds bounds = builder.build();

Now obtain CameraUpdateFactory:

int padding = 0; // offset from edges of the map in pixels
CameraUpdate cu = 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);

You can do something like this. What you have to do is to iterate trough your markers and find the outer most coordinates.

LatLngBounds bounds = new LatLngBounds(southWest, northEast);

mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, MAP_PADDING));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!