我试图弄清楚如何将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];
您是否必须首先设置地图的区域?
答案 0 :(得分:14)
您需要分配并初始化point
:
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];