问题描述
- 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.
解决方案
试试:
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;}
时间: 2025-01-20 17:15:00