Restrict the dragging of SKMapView to a certain city

后端 未结 1 741
终归单人心
终归单人心 2021-01-20 12:34

I am trying to restrict dragging of SKMapView to a certain city.

Here is what I have tried, I had gone through Doc References and open source code. Seem

相关标签:
1条回答
  • 2021-01-20 13:29

    While there is no integrated support for this, you can do a workaround.

    The file from here should replace the one from the Public SDK demo app for viewing the workaround (MapDisplayViewController.m).

    The idea is that you can get the bounding box information of a city/country from the Maps.json provided by us. Then you need to implement the following callback:

    - (void)mapView:(SKMapView *)mapView didChangeToRegion:(SKCoordinateRegion)region { 
        if (self.bbox) { 
            if ([self.bbox containsLocation:region.center]) { 
                self.previousRegion = region; 
            } else { 
                [self.mapView animateToLocation:self.previousRegion.center withDuration:0.2]; 
            } 
        } 
    } 
    

    This implementation ensures that when the user pans out of the bounding box of a city/country he will be moved back to the previous region contained by the bounding box.

    Zoom level restrictions: restricting the zoom level is possible through the zoomLimits property of the SKMapsSettings:

       SKMapZoomLimits zoomLimits; 
        zoomLimits.mapZoomLimitMin = 5.0f; 
        zoomLimits.mapZoomLimitMax = 14.0f; 
        self.mapView.settings.zoomLimits = zoomLimits;
    
    0 讨论(0)
提交回复
热议问题