简体   繁体   中英

how can i draw line on mkmapview

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

I want to add line on mapkit. like this

在此处输入图片说明

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

在此处输入图片说明

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

只需使用self.mapView.displayedAnnotations (这些只是可见的),而不要使用self.mapView.annotations (这些都是已添加的注释)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM