需求
每次車輛狀態(tài)改變時(相當(dāng)于一個定時任務(wù))將需要顯示的marker覆蓋物+自己當(dāng)前位置顯示在屏幕范圍內(nèi)
官方文檔中提供的API
MapStatusUpdateFactory的靜態(tài)方法(用于更新地圖狀態(tài))
// 設(shè)置顯示在屏幕中的地圖地理范圍
static MapStatusUpdate newLatLngBounds(LatLngBounds bounds)
// 設(shè)置顯示在規(guī)定寬高中的地圖地理范圍
static MapStatusUpdate newLatLngBounds(LatLngBounds bounds,int width,int height)
LatLngBounds.Builder中提供的實例方法(用于創(chuàng)建LatLngBounds對象)
// 創(chuàng)建地理范圍對象
LatLngBounds build()
// 讓該地理范圍包含一個地理位置坐標(biāo)
LatLngBounds.Builder include(LatLng point)
思路
利用已有API:1拴驮,將需要顯示的位置點都include到LatLngBounds中春瞬;2,更新地圖狀態(tài)(設(shè)置顯示在屏幕中的地圖地理范圍)
/**
* 設(shè)置顯示在屏幕中的地理范圍
*/
private void zoomToSpan() {
LatLngBounds.Builder builder = new LatLngBounds.Builder();
// 需要顯示的marker點
for (MarkerInfo info : mMarkerInfos) {
builder.include(new LatLng(info.getWD(), info.getJD()));
}
// 我的當(dāng)前位置
builder.include(new LatLng(l.getLatitude(), l.getLongitude()));
LatLngBounds bounds = builder.build();
// 設(shè)置顯示在屏幕中的地圖地理范圍
MapStatusUpdate u = MapStatusUpdateFactory.newLatLngBounds(bounds, mv_statetrasition_map.getWidth(), mv_statetrasition_map.getHeight());
mBaiduMap.setMapStatus(u);
}