android mapbox教程,如何在android中获取MAPBOX中的当前位置

因为我在我的应用程序中使用MAPBOX.我不知道如何获取当前lat和long.我用这种方式获取当前位置.但它显示空对象引用.请帮我解决我的问题

mapView = (MapView)view. findViewById(R.id.mapView);

mapView.setStyleUrl(Style.MAPBOX_STREETS);

mapView.onCreate(savedInstanceState);

//Add a mapBoxMap

mapView.getMapAsync(new OnMapReadyCallback() {

@Override

public void onMapReady(MapboxMap mapboxMap) {

mapboxMap.setMyLocationEnabled(true);

// Set the origin waypoint to the devices location

Position origin = Position.fromCoordinates(mapboxMap.getMyLocation().getLongitude(), mapboxMap.getMyLocation().getLatitude());

Log.i("RR","mapboxMap.getMyLocation();"+origin);

// Log.i("RR","mapboxMap.getMyLocation();"+mapboxMap.getMyLocation().getLongitude());

mapboxMap.getUiSettings().setZoomControlsEnabled(true);

mapboxMap.getUiSettings().setZoomGesturesEnabled(true);

mapboxMap.getUiSettings().setScrollGesturesEnabled(true);

mapboxMap.getUiSettings().setAllGesturesEnabled(true);

}

});

解决方法:

mapboxMap.setMyLocationEnabled(真);已被弃用.

您需要使用locationEngine来获取lat和long

locationEngine = new LostLocationEngine(MainActivity.this);

locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);

locationEngine.setInterval(5000);

locationEngine.activate();

Location lastLocation = locationEngine.getLastLocation();

使用lastLocation.getLatitude(),lastLocation.getLongitude()

标签:android,mapbox,mapbox-android

来源: https://codeday.me/bug/20190607/1195715.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值