0
我一直在試圖讓地圖上顯示多個地圖,但它不起作用。誰能幫我嗎?我正在使用下面的代碼:添加地圖註釋
- (void)viewDidLoad
{
// Set some coordinates for our position (Buckingham Palace!)
CLLocationCoordinate2D location;
location.latitude = (double) 51.501468;
location.longitude = (double) -0.141596;
// Add the annotation to our map view
MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Buckingham Palace" andCoordinate:location];
[self.mapView addAnnotation:newAnnotation];
}
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500);
[mv setRegion:region animated:YES];
[mv selectAnnotation:mp animated:YES];
}
在viewDidLoad中,檢查mapView是否爲零。 didAddAnnotationViews會被調用嗎(把NSLog放進去檢查)? – Anna 2012-02-05 15:40:46