百度地图切换罗盘后不能正北

祁嘉言
2023-12-01

新API切换罗盘不再自动正北,为了支持更多的交互吧。

https://blog.csdn.net/niuba123456/article/details/81124739

使用 MapStatus 更新 rotete 旋转,overlook 鸟瞰。
Button button_location_mode;
button_location_mode = (Button) findViewById(R.id.button_location_mode);
button_location_mode.setOnClickListener(onClickListener);
LocationMode locationMode;
locationMode = LocationMode.NORMAL;
MapView mMapView = null;
mMapView = (MapView) findViewById(R.id.bmapView);
BaiduMap mBaiduMap;
mBaiduMap = mMapView.getMap();
mBaiduMap.setMyLocationEnabled(true);
mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(locationMode, true, mCurrentMarker));

OnClickListener onClickListener = new OnClickListener() {
    @Override
    public void onClick(View v) {
	switch (locationMode) {
	case NORMAL:
            button_location_mode.setText("跟随");
	    locationMode = LocationMode.FOLLOWING;
	    mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(locationMode, true, mCurrentMarker));
            mBaiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus(new MapStatus.Builder(mBaiduMap.getMapStatus()).rotate(0).build()));
            mBaiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus(new MapStatus.Builder(mBaiduMap.getMapStatus()).overlook(0).build()));
	    break;
	case COMPASS:
            button_location_mode.setText("标准");
	    locationMode = LocationMode.NORMAL;
	    mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(locationMode, true, mCurrentMarker));
            mBaiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus(new MapStatus.Builder().rotate(0).build()));
            mBaiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus(new MapStatus.Builder().overlook(0).build()));
	    break;
	case FOLLOWING:
            button_location_mode.setText("罗盘");
            locationMode = LocationMode.COMPASS;
	    mBaiduMap.setMyLocationConfiguration(new MyLocationConfiguration(locationMode, true, mCurrentMarker));
	    break;
	}
    }
};

 

 类似资料: