在实际的项目开发中,老大要求所有的mark点都要求在百度地图上显示出来,然后我更具自己的理解,在百度google上搜索 百度地图缩放级别自适应结果,发现有很多的博客都有写,也许是我太渣,都不符合我的要求,都不能用,没办法只能自己一个人默默的看API文档,
结果也没有找到怎么算出zoom的合适缩放等级,不过发现一个状态工厂 类里面能做到把所有的点都放在手机屏幕上
代码如下
if(position==null){
return;
}
if(!isfirstsetzoom){
return;
}
LatLngBounds.Builder builder2 = new LatLngBounds.Builder();
for(WaybillModel.TaskBean s: position){
String po[] = s.getGisxy().split(",");
LatLng la = new LatLng(Double.parseDouble(po[1]), Double.parseDouble(po[0]));
builder2 = builder2.include(la);
}
builder2 = builder2.include(laa);
LatLngBounds latlngBounds = builder2.build();
latlngBounds.getCenter();
MapStatusUpdate u = MapStatusUpdateFactory.newLatLngBounds(latlngBounds,baidumap.getWidth(),baidumap.getHeight());
mBaiduMap.animateMapStatus(u);
具体原理是用过计算把西北点和东南点算出来
LatLngBounds 是放西北点和东南点
MapStatusUpdate u = MapStatusUpdateFactory.newLatLngBounds(latlngBounds,baidumap.getWidth(),baidumap.getHeight());
通过上面方法来实现所有点都在屏幕内
MapStatusUpdateFactory.newLatLngBounds
MapStatusUpdateFactory.newLatLngBounds
MapStatusUpdateFactory.newLatLngBounds
MapStatusUpdateFactory.newLatLngBounds
MapStatusUpdateFactory.newLatLngBounds
MapStatusUpdateFactory.newLatLngBounds
MapStatusUpdateFactory.newLatLngBounds