Search code examples
iosmkmapviewcore-locationmkpolyline

Polyline for distance covered and actual distance :ios


Is there any way to draw a polyline with source and destination point and then have another polyline for distance covered.

I have drawn the dotted polyline for actual route but could not found a way to draw the another line for distance covered. I can plot the annotation marker for current location on route but also change the color of polyline for distance covered.


Solution

  • Since these I was drawing two different lines, one using direction and another using the ployline I can set title properties and check overlay.title, following code did the trick.

    - (MKOverlayRenderer *)mapView:(MKMapView *)mapView  rendererForOverlay:(id <MKOverlay>)overlay
    {
    [self resetTimer];
    if ([overlay isKindOfClass:[MKTileOverlay class]]) {
        return [[MKTileOverlayRenderer alloc] initWithOverlay:overlay];
    }else if ([overlay isKindOfClass:[MKPolyline class]]) {
        MKPolylineRenderer* renderer = [[MKPolylineRenderer alloc] initWithPolyline:(MKPolyline*)overlay];
        if([overlay.title isEqualToString:@"MyLine"]) {
            [renderer setStrokeColor:[UIColor blueColor]];
            [renderer setLineWidth:3.0];
    
            [renderer setStrokeColor:[UIColor blueColor]];
        }else{
            [renderer setStrokeColor:[UIColor redColor]];
            [renderer setLineWidth:4.0];
            [renderer setLineDashPattern:@[@2, @5]];
            [renderer setStrokeColor:[UIColor redColor]];
        }
        return renderer;
    }
    return nil;
    }