I have multiple arrays that I want to iterate over and plug in as values later in my code for markers on a map. I have the markers populated but can't figure out how to apply the text marker title and subtitle to the marker associated with the location.
iOS and Swift 2
edit: using Mapbox iOS SDK as well.
How do I write the for loop that will do this?
My code trimmed down so far.
Arrays taken from geojson file:
//place variable to array of strings
var place = [String]()
//result from this array ["park", "playground", "parking"]
//pass variable to array of strings
var pass = [String]()
//result from this array ["True", "False", ""]
I have also done this with latitude and longitude but won't add that here. But I do need to add the for loop for it.
//lat and long is served and then all the r,z points, then another lat, long...need to fix this and it may work...
for var (i,x) in zip(lat, long) {
print(i)
print(x)
//print(i + ", " + x)
// String to double conversion
let lati = NSString(string: i).doubleValue
let longi = NSString(string: x).doubleValue
var point = MGLPointAnnotation()
point.coordinate = CLLocationCoordinate2D(latitude: lati, longitude: longi)
let r = place
print(r)
point.title = r
print(r)
let z = pass
print(z)
point.subtitle = z
mapView.addAnnotation(point)
}
So the markers are all added correctly to the map based on lat and long. The marker text however is only added once, and uses the last record served. I am betting I am missing something simple here, as I am newish to coding with Swift 2.
I am receiving this error message "Cannot assign value of type '[String]' to type 'String?'" associated with this line "point.title = r" and this line "point.subtitle = z" which complicates things.
Any suggestions will be greatly appreciated.
If you need more information I can edit as needed but hopefully you have everything you need to help me set up this for loop.