0

i want set a rect on top of the polyline route on my map.

this is what exactly i'm trying to do:

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

i have problem with this line of code :

[self.mapView.visibleMapRect = route.boundingMapRect];

i get the "Expected identifier" error. what is wrong with this line of code? is that the correct way to set an Mkrect for an MKPolyline route?

thanks!

Max_Power89
  • 1,710
  • 1
  • 21
  • 38

2 Answers2

0

That's not how you write objective-C, try this

self.mapView.visibleMapRect = route.boundingMapRect;

or

[self.mapView setVisibleMapRect:route.boundingMapRect animated:YES];
Craig
  • 8,093
  • 8
  • 42
  • 74
  • yes,the method work correctly, but the effect is not what i expected, it don't center the map in the center of route. any suggestion? – Max_Power89 Sep 17 '13 at 07:01
0

i have solved with this tow line of code:

MKMapRect test = MKMapRectInset(route.boundingMapRect, -route.boundingMapRect.size.height/2, -route.boundingMapRect.size.width/2);
    [self.mapView setVisibleMapRect:test animated:YES];
Max_Power89
  • 1,710
  • 1
  • 21
  • 38