核心代码
private void initMap() {
mBaiduMap = mMapView.getMap(); // 获取BaiduMap对象
mMapView.removeViewAt(1); // 去掉百度logo
mBaiduMap.setMyLocationEnabled(false); //不显示我的位置,样覆盖物代替
LatLngBounds.Builder b = new LatLngBounds.Builder();
for (SchoolBranchBean sb : mJxBranchs.getJxBranchs()) {
LatLng pt = new LatLng(sb.getPointY(),sb.getPointX());
BitmapDescriptor bitmap = BitmapDescriptorFactory
.fromResource(R.drawable.ic_jiaxiao_position);
//构建MarkerOption,用于在地图上添加Marker
OverlayOptions option = new MarkerOptions()
.position(pt)
.icon(bitmap);
//在地图上添加Marker,并显示
mBaiduMap.addOverlay(option);
b.include(pt);
}
LatLng latLng_center = b.build().getCenter();//核心代码
MapStatusUpdate mapStatus1 = MapStatusUpdateFactory.newLatLngZoom(latLng_center, 15);
mBaiduMap.setMapStatus(mapStatus1);
}
效果图