1
我在我的項目中使用OCMapView。 OCMapView是Map Kit cluster pinpoints.我如何在mkmapview上畫線
我想在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];
});
你可以看到我的疊加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