下面是我的代码,用于将我的自定义注释加载到一个数组中,然后使用 addAnnotations 将此数组添加到我的地图中。我的地图上没有任何图钉。如果我替换[annotations addObject:annotation];
为[annotations addObject:item.placemark];
我会得到别针,但它们不是我的自定义注释。我有一个名为 Annotation 的 customAnnotation 类。我究竟做错了什么?
NSMutableArray *annotations = [NSMutableArray array];
[response.mapItems enumerateObjectsUsingBlock:^(MKMapItem *item, NSUInteger idx, BOOL *stop) {
// if we already have an annotation for this MKMapItem,
// just return because you don't have to add it again
for (id<MKAnnotation>annotation in mapView.annotations)
{
if (annotation.coordinate.latitude == item.placemark.coordinate.latitude &&
annotation.coordinate.longitude == item.placemark.coordinate.longitude)
{
return;
}
}
// otherwise add it
Annotation *annotation = [[Annotation alloc] initWithPlacemark:item.placemark];
annotation.title = mapItem.name;
annotation.subtitle = mapItem.placemark.addressDictionary[(NSString *)kABPersonAddressStreetKey];
[annotations addObject:annotation];
[self.mapView addAnnotations:annotations];