为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕桂英4014372 2019-10-14 09:43:05
我有10个标记GoogleMap。我想尽可能放大并保持所有标记在视野中吗?在早期版本中,可以从中实现,zoomToSpan()但是在v2中,我不知道该如何做。此外,我知道需要显示的圆的半径。
查看完整描述

3 回答

?
弑天下

TA贡献1818条经验 获得超7个赞

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 screen


CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding);


mMap.animateCamera(cu);


查看完整回答
反对 回复 2019-10-14
  • 3 回答
  • 0 关注
  • 390 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信