Brandon
Brandon

Reputation: 2171

Map JSON Array Coordinates into a Map View

I have done a lot of digging, but I can't seem to find a good resource on how to do something that should be pretty simple.

I have a set of lat/lon coordinates that I would like to drop on a map in iOS6. The coordinates are returned in JSON format (from a database). JSON returns the a set of coordinates as well as the name of a location.

Does anyone know how to plug the JSON array into a map view? it doesn't sound that difficult, but I can't find it documented well. Any help would be great. Thank you!

Upvotes: 0

Views: 1215

Answers (1)

oiledCode
oiledCode

Reputation: 8649

I suppose that your json is something like this :

[ {long : 53.58448, lat : -9.8445}, .... ]

Then :

for(NSDictionary *location in locationArray){
  CLLocationCoordinate2D  point;
  point.latitude  = location[@"lat"];
  point.longitude = location[@"long"];
  AddressAnnotation *a = [[AddressAnnotation alloc] initWithCoordinate:point]; 
  [mapView addAnnotation:a];
  [a release];
}

Upvotes: 2

Related Questions