I need to show on my MkMapView about 10 locations (and respective annotations) and after pressing a button I need to add new different annotations according to different JSO
What is also really important to note (because it was very hard to find that error and I sat the whole last night in front of this...) is to check if your object that conforms to MKAnnotation has some master base class that imlements the methods isEqual and / or hash on only the data of the base class and you do not overwrite that in your base class. This was my problem and thus isEqual returned YES for all annotations and THUS it showed always only one annotation on the map. I couldn't find any hint on the internet about this so I will leave at least this comment here for poor people in the same situation.
In parseMethod
, change this:
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
for (int l=0; l<[locations count]; l++) { // HERE I CAN SEE ONLY A SINGLE LOCATION!
annotation.coordinate = [locations[l] coordinate];
NSLog(@"%f - %f", annotation.coordinate.latitude, annotation.coordinate.longitude); // here I control IF app parses all the values of coordinates
[map addAnnotation: annotation];
}
to this:
for (int l=0; l<[locations count]; l++) { // HERE I CAN SEE ONLY A SINGLE LOCATION!
//create a NEW annotation for each location...
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = [locations[l] coordinate];
NSLog(@"%f - %f", annotation.coordinate.latitude, annotation.coordinate.longitude); // here I control IF app parses all the values of coordinates
[map addAnnotation: annotation];
}
Move the MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]
to inside the for-loop so that a new annotation object is created for each location.
The existing code there creates a single annotation object and just keeps modifying its coordinate.