ios - Custom annotations not loading into array? -
below code loading custom annotations array , adding array map using addannotations. not getting pins on map. if replace [annotations addobject:annotation]; [annotations addobject:item.placemark]; pins not custom annotations. have customannotation class called annotation. doing wrong?
nsmutablearray *annotations = [nsmutablearray array]; [response.mapitems enumerateobjectsusingblock:^(mkmapitem *item, nsuinteger idx, bool *stop) { // if have annotation mkmapitem, // return because don't have add again (id<mkannotation>annotation in mapview.annotations) { if (annotation.coordinate.latitude == item.placemark.coordinate.latitude && annotation.coordinate.longitude == item.placemark.coordinate.longitude) { return; } } // otherwise add 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];
the problem, quite simply, can (a) problem adding annotations; or (b) problem showing annotations. suspected former (given weird indentation, suspected might have problem asynchronous call didn't share us), given works fine if use placemark instead of annotation, have suspect problem must rest in showing of annotations (namely viewforannotation).
i'd first suggest diagnostic work. can confirm whether annotations being added logging count of self.mapview.annotations before , after addannotations call. i'd suspect (based upon you've said) you'll see count go up.
i take @ viewforannotation, , make sure it's handling annotation class properly. have if ([annotation iskindofclass:...) logic, maybe have issue there. it's hard on basis of small snippet of code shared us.
Comments
Post a Comment