如何使用MKPointAnnotation向MKMapView添加注释?

时间:2011-11-02 22:24:00

标签: ios objective-c ios4 mapkit

我试图弄清楚如何将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];

您是否必须首先设置地图的区域?

1 个答案:

答案 0 :(得分:14)

您需要分配并初始化point

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