Mapbox LoactionComponent返回位置问题

时间:2019-05-03 17:05:13

标签: java android mapbox

使用LocationComponent在地图上显示用户位置,无需导航。我的组件总是每20秒返回一次位置,即使我尝试通过不同的时间间隔传递一次locationRequest。

这是针对最新版本的Mapbox的版本,对不起,但我尝试了许多不同的方法

 @SuppressWarnings({"MissingPermission"})
    private void enableLocationComponent() {
        if (parentActivity != null) {
            if (PermissionsManager.areLocationPermissionsGranted(parentActivity)) {
                LocationComponentOptions options = LocationComponentOptions.builder(getActivity())
                        .trackingGesturesManagement(true)
                        .accuracyColor(ContextCompat.getColor(getContext(), R.color.colorBlueLight))
                        .build();

                //----- Prueba
                LocationComponentActivationOptions locationComponentActivationOptions = LocationComponentActivationOptions
                        .builder(parentActivity,  map.getStyle())
//                        .locationEngine(locationEngine)
//                        .locationEngineRequest(request)
                        .locationComponentOptions(options)
                        .useDefaultLocationEngine(true)
                        .build();

                // Get an instance of the component
                locationComponent = map.getLocationComponent();

                // Activate with options
               // locationComponent.activateLocationComponent(parentActivity, map.getStyle(), options);


                // Prueba
                locationComponent.activateLocationComponent(locationComponentActivationOptions);

                // Enable to make component visible
                locationComponent.setLocationComponentEnabled(true);

                // Set the component's camera mode
                locationComponent.setCameraMode(CameraMode.TRACKING_GPS);
                locationComponent.setRenderMode(RenderMode.GPS);
               // locationComponent.setLocationEngine(locationEngine);
                initializeLocationEngine();
                makeMyLocation();

            } else {
                mapView.setEnabled(false);
                permissionsManager = new PermissionsManager(this);
                permissionsManager.requestLocationPermissions(parentActivity);
            }
        }
    }

然后我通过我的请求:

   @SuppressLint("MissingPermission")
    private void initializeLocationEngine() {
        if(getParentActivity().getState() == STATE_AVAILABLE){
            interval = intervalAvailable;
        }else{
            interval = intervalTravelling;
        }
//        if(locationEngine == null){
//            locationEngine = LocationEngineProvider.getBestLocationEngine(parentActivity);
//        }
        request = buildEngineRequest(interval);
        locationComponent.getLocationEngine().requestLocationUpdates(request, callback, getMainLooper());
 }

我希望能够根据不同情况下我的应用程序的需要传递不同的locationRequests

0 个答案:

没有答案