Note that there are some explanatory texts on larger screens.

plurals
  1. POLearning iOS MapKit - multiple pins on map from NSDictionary
    primarykey
    data
    text
    <p>Attempting to take a NSSDictionary that contains all my locations, titles, and subtitles and enumerate through them and add them to my mapView.The first part seems fine; I read the Plist and can access the various parts. What I'm having problems with is running through the enumeration.</p> <p>The NSLog asking for the title correctly reports that property to the console.</p> <p>In the end,though, I see no pins. In addition, after the NSLog call: </p> <pre><code>NSLog(@"My %i annotations are: %@", self.mapView.annotations.count, self.mapView.annotations); </code></pre> <p>I get in response: </p> <pre><code>"My 1 annotations are: ( "&lt;MKPointAnnotation: 0xd0151f0&gt;" ) </code></pre> <p>Which appears to be just <strong>one</strong> memory location for <strong>one</strong> annotation. <em>Sigh</em>. </p> <p>I'm sure I'm doing something simple and wrong, but would appreciate any help. I've been searching all day, and seen some things that appear to be answers here, but not anything that helps me in this particular construction. </p> <p>Thanks you in advance.</p> <p>The following code is fired off in the main viewController, the first method seen is called at the end of ViewDidLoad.</p> <pre><code>-(void) loadUpLocations{ NSPropertyListFormat format; NSString *errorDesc=nil; //make path to plist in bundle NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"locations2" ofType:@"plist"]; //fill data object with contents of file NSData *myData = [[NSData alloc] initWithContentsOfFile:plistPath]; myLocations=[NSPropertyListSerialization propertyListFromData:myData mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&amp;format errorDescription:&amp;errorDesc]; if (!myLocations) { NSLog(@"Error reading Plist: %@ format: %@", errorDesc,format); } myAnnotation=[[MKPointAnnotation alloc]init]; for (NSString *loc in myLocations) { NSDictionary *value =[myLocations objectForKey:loc]; //NSLog(@"Loc is equal to: %@",loc); //loop through and make annotations myAnnotation.coordinate = CLLocationCoordinate2DMake( [[value objectForKey:@"latitude"] doubleValue], [[value objectForKey:@"longitude"] doubleValue]); myAnnotation.title = [value objectForKey:@"title"]; myAnnotation.subtitle = [value objectForKey:@"subtitle"]; NSLog(@"%@",myAnnotation.title); [self.mapView addAnnotation:myAnnotation]; } NSLog(@"My %i annotations are: %@", self.mapView.annotations.count, self.mapView.annotations); } - (IBAction)zoomToLocation:(id)sender { //set center for zoom MKCoordinateRegion region; region.center=CLLocationCoordinate2DMake(33.75070416856952, -84.37034368515015);; //set level of zoom MKCoordinateSpan span; span.latitudeDelta=.03; span.longitudeDelta=.03; region.span=span; [mapView setRegion:region animated:YES]; } // This gets called every time an annotation is in the map view - (MKAnnotationView *)mapView:mapView viewForAnnotation:annotation{ NSLog(@"in annotationsView"); MKPinAnnotationView *myPins=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myPins"]; myPins.animatesDrop=YES; return myPins; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload