我的MKPolyline有问题。
我已添加此代码,但我看不到任何行。我从带有http请求的网络服务器获取坐标。我将坐标保存为双精度并显示我的注释。
viewcontroller.h中的
@property (nonatomic, retain) MKPolyline *routeLine;
@property (nonatomic, retain) MKPolylineView *routeLineView;
viewcontroller.m中的
CLLocationCoordinate2D coordinateArray[7];
coordinateArray[0] = CLLocationCoordinate2DMake(theCoordinate0.latitude, theCoordinate0.longitude);
coordinateArray[1] = CLLocationCoordinate2DMake(theCoordinate1.latitude, theCoordinate1.longitude);
coordinateArray[2] = CLLocationCoordinate2DMake(theCoordinate2.latitude, theCoordinate2.longitude);
coordinateArray[3] = CLLocationCoordinate2DMake(theCoordinate3.latitude, theCoordinate3.longitude);
coordinateArray[4] = CLLocationCoordinate2DMake(theCoordinate4.latitude, theCoordinate4.longitude);
coordinateArray[5] = CLLocationCoordinate2DMake(theCoordinate5.latitude, theCoordinate5.longitude);
coordinateArray[6] = CLLocationCoordinate2DMake(theCoordinate6.latitude, theCoordinate6.longitude);
self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:7];
[self.mapView setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible
[self.mapView addOverlay:self.routeLine];
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
if(overlay == self.routeLine)
{
if(nil == self.routeLineView)
{
self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine]autorelease];
self.routeLineView.fillColor = [UIColor redColor];
self.routeLineView.strokeColor = [UIColor redColor];
self.routeLineView.lineWidth = 10;
}
return self.routeLineView;
}
return nil;
}
答案 0 :(得分:0)
您是否确认您的mapview已连接到屏幕上的mapview(Interface Builder中的IBOutlet)?接下来要检查的是你已经设置了委托。通过在viewForOverlay
函数中放置断点或调试语句来检查这一点。
P.S。使用该代码,您只能绘制一条线。它依赖于self.routeLine
和self.routeLineView
,而您只有其中一个。