0

我会在我的地图视图中插入一条折线!我是这样做的

 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。怎么了?

4

2 回答 2

1

C 中的数组索引从索引 0 开始,而不是 1:

CLLocationCoordinate2D coord[2];
coord[0].latitude = 45.42207;
coord[0].longitude = 9.123888;
coord[1].latitude = 45.422785;
coord[1].longitude = 9.12377;
于 2013-03-25T09:45:22.723 回答
0

尝试这个

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;
}
于 2013-03-25T09:57:37.373 回答