在實際的項目開發中,老大要求所有的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