Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-02-2010, 09:43 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 3
adamstorr is on a distinguished road
Default Place Annotations on Map with NSDictionary/NSArray?

Hi Everyone,

Thanks for the help in advance... this one has been killing me for the past couple of hours.

I am currently pulling in a JSON feed and storing it in a NSDictionary & NSArray. I'm trying to add an annotation for each item being pulled in (time, type, latitude, and longitude). So far, I can extract each value from the Array and have them all repeat with a "for" in the console (see code below).

How to I store these values as an annotation? Any help would be great.

Below is my failed attempt...

Code:
- (void)viewDidLoad {
  [super viewDidLoad];

 // Download JSON Feed
 NSDictionary *feed = [self downloadFeed];
 NSArray *streams = (NSArray *)[feed valueForKey:@"stream"];


 [mapView setMapType:MKMapTypeStandard];
 [mapView setZoomEnabled:YES];
 [mapView setScrollEnabled:YES];
 MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
 region.center.latitude = 29.719023;
 region.center.longitude = -114.157110;
 region.span.longitudeDelta = 0.01f;
 region.span.latitudeDelta = 0.01f;
 [mapView setRegion:region animated:YES]; 

 [mapView setDelegate:self];

 int Info;
 for (Info = 0; Info < streams.count; Info++) {
  NSDictionary *stream = (NSDictionary *)[streams objectAtIndex:Info];
  NSLog(@"Time: %@", [stream valueForKey:@"TheTime"]); 
  NSLog(@"Type: %@", [stream valueForKey:@"Type"]); 
  NSLog(@"Longitude: %@", [stream valueForKey:@"Longitude"]); 
  NSLog(@"Latitude: %@", [stream valueForKey:@"Latitude"]); 

  NSString *getLat = [[NSString alloc] initWithFormat: @"%@", [stream valueForKey:@"Latitude"]];
  NSString *getLong = [[NSString alloc] initWithFormat: @"%@", [stream valueForKey:@"Longitude"]];

  NSString *getCoord = [[NSString alloc] initWithFormat: @"{%@,%@}", getLat, getLong];
  getCoordinates = getCoord;


  DisplayMap *ann = [[DisplayMap alloc] init]; 
  ann.title = @"%@", [stream valueForKey:@"TheTime"];
  ann.subtitle = @"%@", [stream valueForKey:@"Type"]; 
  ann.coordinate = getCoordinates;

  [mapView addAnnotation:ann];

  }
}
adamstorr is offline   Reply With Quote
Old 11-03-2010, 01:24 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 3
adamstorr is on a distinguished road
Default

I think I found my issue... I'm now trying "initWithCoordinates" but I'm getting an error saying its not a true declaration.

Help!
adamstorr is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, nsarray, nsdictionary

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 345
12 members and 333 guests
7twenty7, chiataytuday, condor304, Creativ, Domele, dreamdash3, laureix68, LEARN2MAKE, mistergreen2011, mottdog, palme2elie, Paul Slocum
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,660
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, laureix68
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0