2 developerwab developerWab 于 2013.03.27 14:43 提问

mapView中添加polyline

想在MapView中添加Polyline。代码如下:

CLLocationCoordinate2D coord[2];
coord[1].latitude = 45.42207;
coord[1].longitude = 9.123888;
coord[2].latitude = 45.422785;
coord[2].longitude = 9.12377;

MKPolyline *polyline = [[MKPolyline alloc] init];
polyline = [MKPolyline polylineWithCoordinates:coord count:2];

[self.mapView addAnnotation:polyline];

但是报错: EXC_BAD_ACCESS.

1个回答

loFataMer
loFataMer   2013.03.27 15:24
已采纳

试试:

CLLocationCoordinate2D coord[2];
coord[0].latitude = 45.42207;
coord[0].longitude = 9.123888;
coord[1].latitude = 45.422785;
coord[1].longitude = 9.12377;

MKPolyline *polyline = [[MKPolyline alloc] init];
polyline = [MKPolyline polylineWithCoordinates:coord count:2];


- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {

    MKPolylineView *polyLineView = [[MKPolylineView alloc] initWithPolyline:polyline];
    polyLineView.fillColor = [UIColor blueColor];
    polyLineView.strokeColor = [UIColor greenColor];
    polyLineView.lineWidth = 7;
    return polyLineView;
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!