// 添加定位图层
mLocationOverlay = new MyLocationOverlay(this, mMapView);
mMapView.getOverlays().add(mLocationOverlay);
public void onLocationChanged(Location location) {
if (location != null) {
pt = new GeoPoint((int) (location.getLatitude() * 1e6),
(int) (location.getLongitude() * 1e6));
// mMapView.getController().animateTo(pt);//  = 0;// 本地标记
mSearch.reverseGeocode(pt);// ni地址解析
Toast.makeText(paisong2.this, "本地移动onlocation",
Toast.LENGTH_LONG).show();
upload(pt);
}
}
 mMapView.getController().animateTo(pt);这一句加在onLocationChanged里面的话,以后每次一移动地图就跑到当前位置了,可是我只想第一次显示并移动到当前位置?
 mMapView.getController().animateTo(pt);加在oncreate方法里面又会发生错误,请问要怎么解决??

解决方案 »

  1.   

    看百度API说明:当前位置:MyLocationOverlayhttp://dev.baidu.com/wiki/imap/index.php?title=Android%E5%B9%B3%E5%8F%B0/%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97#.E5.BD.93.E5.89.8D.E4.BD.8D.E7.BD.AE.EF.BC.9AMyLocationOverlay
    // 初始化Location模块
    mLocationManager = mBMapMan.getLocationManager();
    // 通过enableProvider和disableProvider方法,选择定位的Provider
    // mLocationManager.enableProvider(MKLocationManager.MK_NETWORK_PROVIDER);
    // mLocationManager.disableProvider(MKLocationManager.MK_GPS_PROVIDER);
    // 添加定位图层
    MyLocationOverlay mylocTest = new MyLocationOverlay(this, mMapView);
    mylocTest.enableMyLocation(); // 启用定位
    mylocTest.enableCompass(); // 启用指南针
    mMapView.getOverlays().add(mylocTest);
      

  2.   

    楼上的这样只能标识本地位置,不能跳啊。如果在onLocationChanged里面加上 mMapView.getController().animateTo(pt);才能跳转,但是这样每次都会跳转,我只想第一次跳转啊,为什么这句话加到oncreate方法里面会出错,求解!!