display route on iOS 7 maps: addOverlay has no effect

旧巷老猫 提交于 2019-11-28 18:22:27
Max_Power89

after a day of research i have solved with this 3 steps:

  1. Set the delegate (self.mapView.delegate = self).
  2. import the MKMapViewDelegate
  3. Implemente the new iOS7 MapView delegate method: - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay(id<MKOverlay>)overlay:

this is my implementation:

- (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];
        return routeRenderer;
    }
    else return nil;
}

this method is automatically called by the delegate when you add the polyline on the map.

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