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
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;