Title: How would I display an array of annotations?
Tags: ios;swift;parse-platform;mapkit
Question: I am retrieving an array of longitudes and latitudes from parse, and I want to create x number of annotations based on how many coordinate points there are in the database. I can currently retrieve one, but how would I do it with many? "Coordinates" is an object in parse. Would I have to create an array of MKPointAnnotation? How would I create annotations based on the number retrieved from parse?
query.findObjectsInBackgroundWithBlock { (objects: [PFObject]?, error: NSError?) -&gt; Void in
if error == nil{
for objecters in objects!{
if let latit = objecters["Coordinates"]["Latitude"]{
print(lat)
self.latitudepoint = latit as! String
self.map.reloadInputViews()
}
if let longi = objecters["Coordinates"]["Longitude"]{
print(long)
self.longitudepoint = longi as! String
self.map.reloadInputViews()
}
}
}
let lonlat = CLLocationCoordinate2D(
latitude: Double(self.latitudepoint)!,
longitude: Double(self.longitudepoint)!
)
let annotation = MKPointAnnotation()
annotation.coordinate = lonlat


Here is another answer: Assuming the objectsarray will have all the coordinates, you can for each step of this for objecters in objects! place the correspondent MKPointAnnotation in the Map.

Here is another answer: You can iterate over your array and create annotation for each of the point and add it to the map
for objecters in objects!{
if let latit = objecters["Coordinates"]["Latitude"]{
self.latitudepoint = latit as! String
self.map.reloadInputViews()
else {
continue
if let longi = objecters["Coordinates"]["Longitude"]{
self.longitudepoint = longi as! String
self.map.reloadInputViews()
else {
continue
var annotation = MKPointAnnotation()
var coord = CLLocationCoordinate2D(latitude: Double(self.latitudepoint)!,longitude: Double(self.longitudepoint)!)
mapView.addAnnotation(annotation)
This will add annotations to your map and then you can use setRegionproperty or centre the map at appropriate point.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:02/01/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<ios><swift><parse-platform><mapkit>', 'Title': 'How would I display an array of annotations?', 'ViewCount': 73, 'id': 35122010, 'user_AboutMe': None, 'user_AccountId': 7453699.0, 'user_DisplayName': 'stackerleet', 'user_Reputation': 518.0, 'user_Views': 78.0, 'user_id': 5667567.0}}