Reputation: 5
I would insert in my mapview an polyline! I made it in this way
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];
But don't work and there's this error: EXC_BAD_ACCESS. What's it wrong?
Upvotes: 0
Views: 2962
Reputation: 3455
try this
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;
}
Upvotes: 0
Reputation: 539685
Array indices in C start with index 0, not 1:
CLLocationCoordinate2D coord[2];
coord[0].latitude = 45.42207;
coord[0].longitude = 9.123888;
coord[1].latitude = 45.422785;
coord[1].longitude = 9.12377;
Upvotes: 1