I am inserting some annotations that are coming from a json server, but I wanted to check if the annotation is already on the map, if so, does not add it again. For they are being added on each other , have someone help me solve this problem?
my code:
// adiciona produtos ao mapa
- (void)adicionaAnnotationsNoMapa:(id)objetos{
NSMutableArray *annotationsPins = [[NSMutableArray alloc] init];
for (NSDictionary *annotationDeProdutos in objetos) {
CLLocationCoordinate2D location;
AnnotationMap *myAnn;
myAnn = [[AnnotationMap alloc] init];
location.latitude = [[annotationDeProdutos objectForKey:@"latitude"] floatValue];
location.longitude = [[annotationDeProdutos objectForKey:@"longitude"] floatValue];
myAnn.coordinate = location;
myAnn.title = [annotationDeProdutos objectForKey:@"name"];
myAnn.subtitle = [NSString stringWithFormat:@"R$ %@",[annotationDeProdutos objectForKey:@"price"]];
myAnn.categoria = [NSString stringWithFormat:@"%@", [annotationDeProdutos objectForKey:@"id_categoria"]];
myAnn.idProduto = [NSString stringWithFormat:@"%@", [annotationDeProdutos objectForKey:@"id"]];
[annotationsPins addObject:myAnn];
}
[self.mapView addAnnotations:annotationsPins];
}