developerWab
2013-03-27 06:43
采纳率: 69.1%
浏览 2.1k

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 2013-03-27 07: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;
    }
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题