我正在尝试在 Android 设备上使用 LocationEngine 获取用户位置,但是当我为应用程序加注星标时,用户的标记位于 (0.0, 0.0) 并且永远不会更新它的位置。这怎么可能?
我尝试复制示例位置层
private void enableLocationPlugin() {
// Check if permissions are enabled and if not request
if (PermissionsManager.areLocationPermissionsGranted(this)) {
// Create an instance of LOST location engine
initializeLocationEngine();
LocationLayerOptions options = LocationLayerOptions.builder(this)
.build();
locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine, options);
locationLayerPlugin.setRenderMode(RenderMode.COMPASS);
locationLayerPlugin.setCameraMode(CameraMode.TRACKING);
locationLayerPlugin.setLocationLayerEnabled(true);
} else {
permissionsManager = new PermissionsManager(this);
permissionsManager.requestLocationPermissions(this);
}
}
private void initializeLocationEngine() {
locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.setInterval(1000);
locationEngine.setFastestInterval(500);
locationEngine.addLocationEngineListener(this);
locationEngine.activate();
locationEngine.requestLocationUpdates();
Location lastLocation = locationEngine.getLastLocation();
if (lastLocation != null) {
setCameraPosition(lastLocation);
locationEngine.addLocationEngineListener(this);
} else {
locationEngine.addLocationEngineListener(this);
}
}
我在 Grandle 中使用这个版本的 MapBox
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-building:0.2.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.12.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:0.5.2'