Pregunta

I have been trying to do this for a while now , but still not able to show multiple annotations. Here is how i am storing data into NSMutableDictionary and then to NSMutableArray in AppDelegate

    // set the values to  mutable dictionary
    [_locationDictionary setObject:latitudeObj forKey:@"latitudeValue"];
    [_locationDictionary setObject:longitudeObj forKey:@"longitudeValue"];
    [_locationDictionary setObject:fromUser forKey:@"fromUser"];


    // add to array
    [_presenceArray addObject:_locationDictionary];

And this i am doing inside another ViewController.

   -(void)getPresenceData { 
   for(NSDictionary *dictObj in appDelegate.presenceArray) // this array that has dictionaries 
 {
      annotation = [[Annotation alloc]init];        // Annotation Class

     annotation.coordinate = CLLocationCoordinate2DMake([[dictObj valueForKey:@"latitudeValue"]doubleValue], [[dictObj valueForKey:@"longitudeValue"]doubleValue]);

     annotation.title = [dictObj objectForKey:@"fromUser"];

     [self.buddyDataArray addObject:annotation];

     NSLog(@"buddy data array is %@", self.buddyDataArray);

     [self.mapView addAnnotations:buddyDataArray];
}
¿Fue útil?

Solución

You could try this way... Make sure in your presenceArray dictionaries are getting stored.

-(void)getPresenceData { 
    for(NSDictionary *dictObj in appDelegate.presenceArray) // this array that has dictionaries 
    {
 annotation = [[Annotation alloc]init];        // Annotation Class
 annotation.coordinate = CLLocationCoordinate2DMake([[dictObj valueForKey:@"latitudeValue"]doubleValue], [[dictObj valueForKey:@"longitudeValue"]doubleValue]);
 annotation.title = [dictObj objectForKey:@"fromUser"];
 [self.mapview addAnnotation:annotation];
    }
}

As you are already looping than you dont need to create array of annotation objects.. You can add directly them to map as i did in above code..

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top