繁体   English   中英

我如何在mkmapview上画线

[英]how can i draw line on mkmapview

我在项目中使用OCMapView OCMapView是Map Kit群集的精确点。

我想在mapkit上添加行。 像这样

在此处输入图片说明

但是我的代码这样做:这不是逻辑上添加到地图上的叠加线。

在此处输入图片说明

我处理这段代码。

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

你可以看到我的叠加降落法

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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