Android Map v2缩放以显示所有标记

我有10个标记GoogleMap。我想尽可能放大并保持所有标记在视野中吗?在早期版本中,可以从中实现,zoomToSpan()但是在v2中,我不知道该如何做。此外,我知道需要显示的圆的半径。



慕桂英4014372
浏览 392回答 3
3回答

弑天下

Google Map V2以下解决方案适用于Android Marshmallow 6(API 23,API 24,API 25,API 26,API 27,API 28)。它也可以在Xamarin中使用。LatLngBounds.Builder builder = new LatLngBounds.Builder();//the include method will calculate the min and max bound.builder.include(marker1.getPosition());builder.include(marker2.getPosition());builder.include(marker3.getPosition());builder.include(marker4.getPosition());LatLngBounds bounds = builder.build();int width = getResources().getDisplayMetrics().widthPixels;int height = getResources().getDisplayMetrics().heightPixels;int padding = (int) (width * 0.10); // offset from edges of the map 10% of screenCameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding);mMap.animateCamera(cu);
打开App,查看更多内容
随时随地看视频慕课网APP