2
I’m inserting some Annotations q are coming from a server JSON
, but I wanted to check if the Annotation is already on the map, if yes, does not add it again. For they are being added over each other. There’s someone who can help me solve this problem?
My code by adding the pins:
// 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];
}
Thank you very much, it worked perfect. I just added a
if
to check if you have anypin
on the map, because he was not able to check the first time because n had nothing on the map. Is there any way I can put the code resolution here? 'Cause I’m new to the stack.– Samuel Carvalho
Great! Consider marking this answer as accepted if you have answered your question. It will help others with the same question.
– Paulo Rodrigues