使用 SKZoonLevelConfiguration 启用自动缩放

Enable automatic zoom with SKZoonLevelConfiguration

情况是这样的,我想设置导航模式,根据当前速度调整缩放路线。查看我的代码:

SKZoomLevelConfiguration[] zoomConfgs = new SKZoomLevelConfiguration[4];
zoomConfgs[0] = new SKZoomLevelConfiguration(0.0f, 10.0f, 15.0f);
zoomConfgs[1] = new SKZoomLevelConfiguration(10.0f, 20.0f, 13.0f);
zoomConfgs[2] = new SKZoomLevelConfiguration(20.0f, 60.0f, 10.0f);
zoomConfgs[3] = new SKZoomLevelConfiguration(60.0f, 100.0f, 8.0f);

SKNavigationSettings navSettings = new SKNavigationSettings();
navSettings.setNavigationType(SKNavigationSettings.SKNavigationType.REAL); 
navSettings.setNavigationMode(SKNavigationSettings.SKNavigationMode.CAR); 
navSettings.setDistanceUnit(SKMaps.SKDistanceUnitType.DISTANCE_UNIT_KILOMETER_METERS);
navSettings.setZoomLevelConfigurations(zoomConfgs);
navSettings.setPositionerVerticalAlignment(-0.25f);

SKNavigationManager.getInstance().setNavigationListener(navListener);
SKNavigationManager.getInstance().setMapView(surfaceView);
surfaceView.getMapSettings().setMapDisplayMode(SKMapSettings.SKMapDisplayMode.MODE_3D);
SKNavigationManager.getInstance().startNavigation(navSettings);
isNavigating = true;

所以这里的事实是当导航被激活时地图没有缩放。可能我做错了什么。

在 2.5 中,此 API 存在问题 - 它已在 2.6 中修复。

这是它在 2.6 中如何工作的代码片段:

    /** 
     * Launches a navigation on the current route 
     */ 
    private void launchNavigation() { 
        if (TrackElementsActivity.selectedTrackElement != null) { 
            mapView.clearTrackElement(TrackElementsActivity.selectedTrackElement); 

        } 
        // get navigation settings object 
        SKNavigationSettings navigationSettings = new SKNavigationSettings(); 
        // set the desired navigation settings 
        navigationSettings.setNavigationType(SKNavigationType.SIMULATION); 
        navigationSettings.setPositionerVerticalAlignment(-0.25f); 
        navigationSettings.setShowRealGPSPositions(false); 

        SKZoomLevelConfiguration[] configurations = new SKZoomLevelConfiguration[2]; 
        configurations[0] = new SKZoomLevelConfiguration(0, 70, 10); 
        configurations[1] = new SKZoomLevelConfiguration(70, 100, 15); 
        navigationSettings.setZoomLevelConfigurations(configurations); 
        // get the navigation manager object 
        SKNavigationManager navigationManager = SKNavigationManager.getInstance(); 
        navigationManager.setMapView(mapView); 
        // set listener for navigation events 
        navigationManager.setNavigationListener(this); 

        // start navigating using the settings 
        navigationManager.startNavigation(navigationSettings); 
        navigationInProgress = true; 
    } 

注意:SKZoomLevelConfigurations中设置的速度值(km/h)与SKNavigationState的当前速度(m/s)相关。 onUpdateNavigationState(SKNavigationState navigationState) 方法在与当前速度相关的数据更新时提供通知。