使用SKZoonLevelConfiguration启用自动缩放

时间:2015-08-20 19:08:11

标签: android navigation skmaps

在这种情况下,我想设置导航模式以根据当前速度调整变焦以进行路由。看我的代码:

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;

因此,这里的事实是当导航被激活时地图不会缩放。可能我做错了。

1 个答案:

答案 0 :(得分:2)

在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)方法在更新与当前速度相关的数据时提供通知。