我很新的programmin開發iPhone應用程序,我想知道爲什麼MKPolyline,我創建與2 MKMapPoints不會出現在我的視圖插入MKMapView。 這裏是我的代碼:爲什麼MKPolyline不顯示在MKMapView上?
- (void)viewDidLoad
{
[super viewDidLoad];
map = [[MKMapView alloc] initWithFrame:self.view.bounds];
MKMapPoint * pointsArray = malloc(sizeof(CLLocationCoordinate2D)*4);
CLLocationCoordinate2D punto1;
punto1.latitude =39.468502;
punto1.longitude =-0.398469;
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc]init];
annotationPoint.coordinate = punto1;
annotationPoint.title = @"Point 1";
MKPointAnnotation *annotationPoint2 = [[MKPointAnnotation alloc]init];
annotationPoint2.coordinate = CLLocationCoordinate2DMake(39.472312,-0.386453);
annotationPoint2.title = @"Point 2";
[map addAnnotation:annotationPoint];
[map addAnnotation:annotationPoint2];
pointsArray[0]= MKMapPointForCoordinate(punto1);
pointsArray[1]= MKMapPointForCoordinate(CLLocationCoordinate2DMake(39.467011,-0.390015));
pointsArray[2]= MKMapPointForCoordinate(CLLocationCoordinate2DMake(39.469926,-0.392118));
pointsArray[3]= MKMapPointForCoordinate(CLLocationCoordinate2DMake(39.472312,-0.386453));
routeLine = [MKPolyline polylineWithPoints:pointsArray count:4];
free(pointsArray);
[map addOverlay:routeLine];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake(39.467011,-0.392515), 1100, 1100);
[map setRegion:region];
[self.view insertSubview:map atIndex:0];
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay
{
MKOverlayView* overlayView = nil;
MKPolylineView * routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine];
routeLineView.fillColor = [UIColor blueColor];
routeLineView.strokeColor = [UIColor orangeColor];
routeLineView.lineWidth = 3;
overlayView = routeLineView;
return overlayView;
}
的註釋是確定,他們正確地顯示在地圖上。 希望有人能幫忙,謝謝!!!