【问题标题】:How to add an annotation to MKMapView using an MKPointAnnotation?如何使用 MKPointAnnotation 向 MKMapView 添加注释?
【发布时间】:2011-11-02 22:24:00
【问题描述】:

我试图弄清楚如何将 MKAnnotation 的实例添加到 MKMapView。我无法弄清楚我做错了什么......在我真正尝试将注释添加到mapView之前,一切似乎都很好。然后我收到一个 SIGABRT 错误。这是我的代码:

lon = [[attributeDict objectForKey:@"long"] doubleValue];
lat = [[attributeDict objectForKey:@"lat"] doubleValue];
 MKPointAnnotation *point;
 CLLocation *theLocation = [[CLLocation alloc]initWithLatitude:lat longitude:lon];
 CLLocationCoordinate2D location;
 location.latitude = lat;
 location.longitude = lon;
 [point setCoordinate:(location)];
 [point setTitle:businessName];

 //ITS RIGHT HERE THAT I GET THE ERROR
 [theMap addAnnotation:point];

你必须先设置地图的区域还是什么?

【问题讨论】:

    标签: ios objective-c ios4 mapkit


    【解决方案1】:

    你需要分配和初始化point:

    MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
    

    【讨论】:

    • 天哪,我觉得自己很笨,我不知道我是怎么错过的。非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    相关资源
    最近更新 更多