2013-10-12 5 views
1

Я использую OCMapView в моем проекте. OCMapView is Map Kit cluster pinpoints.как я могу нарисовать линию на mkmapview

Я хочу добавить строку на mapkit. как этот

enter image description here

Но мой код делает это: это не логично добавить наложения линии на карте.

enter image description here

я обрабатывать этот код.

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]; 
    }); 

вы можете видеть, что мой метод наложения delagate

- (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; 


} 

также я делюсь мой код проекта. Как я могу решить эту проблему ?

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

ответ

0

Просто используйте self.mapView.displayedAnnotations (это только те, которые видны) вместо self.mapView.annotations (все эти аннотации, которые были добавлены).

Смежные вопросы