我想在我的地图上的折线路线上设置一个矩形。
这正是我想要做的:
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolyline class]]) {
MKPolyline *route = overlay;
MKPolylineRenderer *routeRenderer = [[MKPolylineRenderer alloc] initWithPolyline:route];
routeRenderer.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.7];
routeRenderer.lineWidth = 5.0;
[self.mapView.visibleMapRect = route.boundingMapRect];
return routeRenderer;
}
else return nil;
}我对这行代码有问题:
[self.mapView.visibleMapRect = route.boundingMapRect];我得到了“期望的标识符”错误。这行代码有什么问题?这是为MKPolyline路由设置Mkrect的正确方式吗?
谢谢!
发布于 2013-09-17 08:45:33
这不是你写objective-C的方式,试试这个
self.mapView.visibleMapRect = route.boundingMapRect;或
[self.mapView setVisibleMapRect:route.boundingMapRect animated:YES];发布于 2013-09-17 15:30:35
我已经用这两行代码解决了这个问题:
MKMapRect test = MKMapRectInset(route.boundingMapRect, -route.boundingMapRect.size.height/2, -route.boundingMapRect.size.width/2);
[self.mapView setVisibleMapRect:test animated:YES];https://stackoverflow.com/questions/18837393
复制相似问题