display route on iOS 7 maps: addOverlay has no effect

后端 未结 1 1412
既然无缘
既然无缘 2020-12-13 15:24

i want display a point to point route inside my mapView, i use this code for create the route:

- (IBAction)backToYourCar {
    MKPlacemark *sourcePlacemark =         


        
相关标签:
1条回答
  • 2020-12-13 15:53

    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.

    0 讨论(0)
提交回复
热议问题