Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Polylines from over the map Xcode

I am implementing an iphone app. i have a map and array of objects that contains the coordinates to be plotted on the map. And a polyline is drawn between these point. So i want to know how to remove this polyline. not Show/Hide, but remove.

here is my code of how i am drawing it

int pointCount = [routeLatitudes count] / 2; //routeLatitudes is the array that contains the coordinates latitude followed by longitude.

    MKMapPoint* pointArr = malloc(sizeof(MKMapPoint) * pointCount);

    int pointArrIndex = 0;  
    for (int idx = 0; idx < [routeLatitudes count]; idx=idx+2)
    {
        CLLocationCoordinate2D workingCoordinate;       
        workingCoordinate.latitude=[[routeLatitudes objectAtIndex:idx] doubleValue];
        workingCoordinate.longitude=[[routeLatitudes objectAtIndex:idx+1] doubleValue];  
        MKMapPoint point = MKMapPointForCoordinate(workingCoordinate);
        pointArr[pointArrIndex] = point;
        pointArrIndex++;
    }   

    // create the polyline based on the array of points. 
    routeLine = [MKPolyline polylineWithPoints:pointArr count:pointCount];

    [mapView addOverlay:routeLine];
    free(pointArr);  

And to Show/Hide the polylines i created a reference MKOverlayView* overlayView = nil;

overlayView.hidden=false/true;

now i need to know how to remove/delete the drawn polylines.

Thank in advance.

like image 990
fadd Avatar asked Jan 15 '23 15:01

fadd


1 Answers

try this

 [mapView removeOverlays:mapView.overlays];
like image 107
jcesarmobile Avatar answered Jan 18 '23 23:01

jcesarmobile