【问题标题】:Adding Map Annotation添加地图注释
【发布时间】:2012-02-27 08:29:11
【问题描述】:

我一直在尝试让多个地图图钉显示在地图上,但它不起作用。谁能帮我吗?我正在使用下面的代码:

  - (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 是否为 nil。是否调用了 didAddAnnotationViews(将 NSLog 放入其中进行检查)?

标签: iphone xcode xcode4 ios4 mapkit


【解决方案1】:

您是否设置了 mapview 委托?

self.mapView.delegate = self;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-11
    • 2012-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多