当前位置: 代码迷 >> Android >> 百度map定位及移动到中心点的有关问题
  详细解决方案

百度map定位及移动到中心点的有关问题

热度:118   发布时间:2016-05-01 12:08:08.0
百度地图定位及移动到中心点的问题
我的代码:

public class Main extends MapActivity {

// 地图引擎管理
private BMapManager mBMapManager;

// MapView控制
private MapController mMapController;

// MapView
private MapView mMapView;

// 地图覆盖物
private MyLocationOverlay mLocationOverlay;

// 当前经纬度
private GeoPoint myPoint;

// 定位监听
private LocationListener mLocationListener;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        mBMapManager = new BMapManager(getApplication());
        mBMapManager.init("65E876940AFB41F7DC232FFB11DBCECEC948591B", null);
        super.initMapActivity(mBMapManager);
        
        mMapView = (MapView)findViewById(R.id.bmapsView);
        
        // 设置启用内置的缩放控件
        mMapView.setBuiltInZoomControls(true);
        
        // 设定缩放时重新绘制覆盖物
        mMapView.setDrawOverlayWhenZooming(true);
        
        // 得到mMapView的控制权,可以用它控制和驱动平移和缩放
        mMapController = mMapView.getController();
        
        //设置地图zoom级别
        mMapController.setZoom(15);
        
        // 添加定位图层
        mLocationOverlay = new MyLocationOverlay(this, mMapView);
        // 添加定位覆盖物
        mMapView.getOverlays().add(mLocationOverlay);
        
        Drawable marker = getResources().getDrawable(R.drawable.shop);
        mMapView.getOverlays().add(new ShopOverLay(marker, Main.this));
 
        // 注册定位监听
        mLocationListener = new LocationListener() {

public void onLocationChanged(Location mLocation) {

if (mLocation != null) {
double latitude = mLocation.getLatitude();
        double longitude = mLocation.getLongitude();
        
        myPoint = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
        
        mMapController.animateTo(myPoint);
        // 设置地图中心点
  相关解决方案