objective c - Restrict the dragging of SKMapView to a certain city -
i trying restrict dragging of skmapview
city.
here have tried, had gone through doc references , open source code. seems skboundingbox
that.
but piece of code doesn't work. still allows user pan everywhere.
skboundingbox *boundingbox = [skboundingbox boundingboxwithtopleftcoordinate:topleftcoordinate bottomrightcoordinate:bottomrightcoordinate];
while there no integrated support this, can workaround.
the file here should replace 1 public sdk demo app viewing workaround (mapdisplayviewcontroller.m).
the idea can bounding box information of city/country maps.json provided us. need implement 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 when user pans out of bounding box of city/country moved previous region contained bounding box.
zoom level restrictions: restricting zoom level possible through zoomlimits property of skmapssettings:
skmapzoomlimits zoomlimits; zoomlimits.mapzoomlimitmin = 5.0f; zoomlimits.mapzoomlimitmax = 14.0f; self.mapview.settings.zoomlimits = zoomlimits;
Comments
Post a Comment