我正在尝试将MKPolyLine添加到我的mapView中。但是有错误:NSInvalidArgumentException', reason: '-[MKPolylineView boundingMapRect]我的代码:
- (void)addRoad {
[self loadRoude];
[self.mapView addOverlay:self.routeLine];
}
- (void)loadRoude{
MKMapPoint northEastPoint = MKMapPointForCoordinate(self.mapView.userLocation.coordinate);
MKMapPoint southWestPoint = MKMapPointMake(52.142391, 21.055641);
MKMapPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) * 2);
pointArr[0] = northEastPoint;
pointArr[1] = southWestPoint;
self.routeLine = [MKPolyline polylineWithPoints:pointArr count:2];
_routeRect = MKMapRectMake(southWestPoint.x, southWestPoint.y, northEastPoint.x - southWestPoint.x, northEastPoint.y - southWestPoint.y);
free(pointArr);
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;
if(overlay == self.routeLine)
{
if(nil == self.routeLineView)
{
self.routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine];
self.routeLineView.fillColor = [UIColor redColor];
self.routeLineView.strokeColor = [UIColor redColor];
self.routeLineView.lineWidth = 3;
}
overlayView = self.routeLineView;
}
return overlayView;
}有我的问题吗?
编辑
NSLog of self.routeLineView告诉我:outeLiveView = <MKPolylineView: 0x7c956d0; frame = (0 0; 0 0); opaque = NO; layer = <MKOverlayClusterProxyLayer: 0x7c97eb0>>是正常的吗?
EDIT2
NSLog(@"pointArr[0]x = %f",pointArr[0].x);
NSLog(@"pointArr[0]y = %f",pointArr[0].y);
NSLog(@"pointArr[1]x = %f",pointArr[1].x);
NSLog(@"pointArr[1]y = %f",pointArr[1].y);展示:
pointArr[0]x = 149891376.014222
pointArr[0]y = 88510604.996837
pointArr[1]x = 149917951.870020
pointArr[1]y = 88495551.883086这意味着我的指针数组没有零对象。我真的很震惊
发布于 2012-07-10 16:53:56
来自苹果公司的文件:
NSInvalidArgumentException:将无效参数传递给方法时发生的异常的名称,例如需要非零对象的零指针。可在MacOSXv10.0及更高版本中使用。
检查用于初始化routeLineView或任何其他MKPolylineView对象的值。其中一个可能是nil。
https://stackoverflow.com/questions/11417994
复制相似问题