如何在安卓百度地图中显示当前位置



我想在android应用程序中使用百度地图。到目前为止,我已经设法整合了百度地图,但它显示了所有经纬度的静态地图。到目前为止,我所做的是:

public class BaiduMapActivity extends AppCompatActivity{
    @SuppressWarnings("unused")
    private static final String LTAG = BaiduMapActivity.class.getSimpleName();
    private MapView mMapView;
    private BaiduMap mBaiduMap;
    // ********bejing**********
    double lat = 39.9167;
    double longi = 116.3833;
    double shanghaiLat = 31.2000;
    double shangaiLong = 121.5000;
    Context mContext = BaiduMapActivity.this;
    RoutePlanSearch mSearch = null; // 搜索模块,也可去掉地图模块独立使用
    RouteLine route = null;
    OverlayManager routeOverlay = null;
    boolean useDefaultIcon = false;
    private boolean canGetLocation;
    private double singaporeLat = 1.3000;
    private double singaporeLong = 103.8000;
    private double hongkongLat = 22.2783;
    private double hongkongLong = 114.1747;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SDKInitializer.initialize(getApplicationContext());
        setContentView(R.layout.activity_baidu_maps_layout);
        init();
        try {
            mBaiduMap = mMapView.getMap();
            mBaiduMap.setMyLocationEnabled(true);
            MyLocationData locData = new MyLocationData.Builder()
                    .direction(100).latitude(hongkongLat).longitude(hongkongLong).build();  
          //loads same map even if lat long are changed
            mBaiduMap.setMyLocationData(locData);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    private void init() {
        mMapView = (MapView) findViewById(R.id.baidu_mapview_id);
    }
    @Override
    protected void onPause() {
        super.onPause();
        mMapView.onPause();
    }
    @Override
    protected void onResume() {
        super.onResume();
        mMapView.onResume();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapView.onDestroy();
    }
}

如何加载地图不同的时间长?

你应该改变这一行:

MyLocationData locData = new MyLocationData.Builder().direction(100).latitude(hongkongLat).longitude(hongkongLong).build();

你可以把你的hongkongLat改成你的lat,把hongkongLong改成你的long。

但需要注意的是,百度地图使用了不同的时/长系统。他们提供API将"Google的lat/lng"翻译成"百度的lat/lng"。然而,使用谷歌地图总是更容易。

相关内容

  • 没有找到相关文章

最新更新