Restrict the dragging of SKMapView to a certain city

 ̄綄美尐妖づ 提交于 2019-12-20 02:33:16

问题


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. Seems like SKBoundingBox does that.

But this piece of code doesn't work. It still allows user to pan everywhere.

SKBoundingBox *boundingBox = [SKBoundingBox boundingBoxWithTopLeftCoordinate:topLeftCoordinate bottomRightCoordinate:bottomRightCoordinate];

回答1:


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;


来源:https://stackoverflow.com/questions/31781283/restrict-the-dragging-of-skmapview-to-a-certain-city

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!