簡體   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