user3029309
user3029309

Reputation: 11

Parse and add multiple annotations?

i have a Problem with the Annotiations, the Code is ok, but i read with the Variable [i] more than one Username and Location. On the Map i have only the last reading Username and Location Pin. In the Debug Box , he show me all Names and Location, but i have only 1 Pin on the Map.

Here is the Code.

for (int i=1; i<4; ++i) {
[User whereKey:@"index" equalTo:@(i)];
PFObject *test1 = [User getFirstObject];
ann.title = [test1 objectForKey:@"username"] ;
PFGeoPoint *geopoint = [test1 objectForKey:@"currentLocation"];
CLLocationCoordinate2D coord = { geopoint.latitude, geopoint.longitude };
ann.coordinate = coord;

    [MapView addAnnotation:ann];


}

Thanks for your Help ;)

Upvotes: 0

Views: 261

Answers (1)

user467105
user467105

Reputation:

The ann object which you are adding to the map needs to be created separately for each annotation that you add.

In the code shown, the ann object is not being created inside the for loop for each annotation so you end up with only one annotation object with the coordinates of the last item.

Create the ann object (alloc+init) inside the loop before setting the properties on it.

Upvotes: 1

Related Questions