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

Rob*_*Rob 13 objective-c mapkit ios4 ios

我试图弄清楚如何将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];
Run Code Online (Sandbox Code Playgroud)

你必须首先设置地图的区域吗?

小智 14

你需要alloc和init point:

MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
Run Code Online (Sandbox Code Playgroud)

  • 哦,当我感到愚蠢,我不知道我是多么想念那个.非常感谢 (2认同)