0

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!

Brandon
  • 2,163
  • 6
  • 40
  • 64
  • 1
    You don't need to put the array itself into the map view, right - all you need are the points. So you have to parse the array, and then dump all the points on the map. Look at this q/a for how to handle JSON in iOS: http://stackoverflow.com/questions/5813077/iphone-ios-json-parsing-tutorial, and then this q/a will show how to drop a pin on a map: http://stackoverflow.com/questions/7304465/how-add-pin-on-map – Sudipta Chatterjee Feb 10 '13 at 11:29

1 Answers1

2

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];
}
oiledCode
  • 8,589
  • 6
  • 43
  • 59
  • Thanks! does this allow me to make a caption for each of the coordinates? Like when the user clicks on the pin, the name of the location pops up and allows you to forward to a different view? – Brandon Feb 10 '13 at 11:56
  • that's another question have a look at this tutorial http://www.raywenderlich.com/2847/introduction-to-mapkit-on-ios-tutorial – oiledCode Feb 10 '13 at 12:02