1

I am using OCMapView in my project . OCMapView is Map Kit cluster pinpoints.

I want to add line on mapkit. like this

enter image description here

But my code doing this : it's not logical add to overlay line on map .

enter image description here

I handle this code .

CLLocationCoordinate2D *coordinates
    = malloc(sizeof(CLLocationCoordinate2D) * [self.mapView.annotations count]);
    for (int i=0; i<[self.mapView.annotations count]; i++) {
        OCMapViewSampleHelpAnnotation * ann=[annodationArray objectAtIndex:i];
        coordinates[i]=ann.coordinate;


    }
    self.routeLineView=nil;
self.routeLine = [MKPolyline polylineWithCoordinates:coordinates count:self.mapView.annotations.count]; // 
    free(coordinates);
    [self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.mapView addOverlay:self.routeLine];
    });

you can see my overlay delagate method

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay{
    //normally here is circle. 

    if(overlay == self.routeLine)
    {
        if(nil == self.routeLineView)
        {
            self.routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine];
            self.routeLineView.fillColor = [UIColor redColor];
            self.routeLineView.strokeColor = [UIColor redColor];
            self.routeLineView.lineWidth = 3;

        }

        return self.routeLineView;
    }

    return nil;


} 

also I am sharing my project code . How can I solve this problem ?

https://www.dropbox.com/s/q0gtwihtl8o2pom/OCMapView-master.zip

Community
  • 1
  • 1
Erhan Demirci
  • 4,173
  • 4
  • 36
  • 44

1 Answers1

0

Just use self.mapView.displayedAnnotations (these are only the ones visible) instead of self.mapView.annotations (these are all annotations, that were added).

calimarkus
  • 9,955
  • 2
  • 28
  • 48