大家好,我想从 3 个数组中获取数据以创建 map 注释。但是我无法将这 3 个数组中的数据加载到一个类中。这是我的代码:
我的类(class)文件:
import MapKit
class Jobdata: NSObject, MKAnnotation {
let title: String?
let coordinate: CLLocationCoordinate2D
init(title: String, coordinate: CLLocationCoordinate2D) {
self.title = title
self.coordinate = coordinate
super.init()
}
}
这些是我的数组:
var jobNameST = [String]()
var jobLongitudeST = [Double]()
var jobLatitudeST = [Double]()
这是我的位置数组:
let jobLocations = [Jobdata(title: "test", coordinate: CLLocationCoordinate2D(latitude: 30.4692991035765, longitude: -97.7660876))]
我想将这 3 个数组添加到我的位置数组中。
最佳答案
首先你需要创建位置模型 我希望所有数组都有相同数量的记录 如果没有请先检查一下
struct Location
{
var title: String?
var latitude: Double?
var longitude: Double?
init(title: String, latitude: Double, longitude: Double) {
self.title = title
self.latitude = latitude
self.longitude = longitude
}
}
根据给定的标题、纬度和经度数组创建位置模型数组
func getLocations() -> [Location] {
var locations = [Location]()
for (index, value) in jobNameST.enumerated() {
let location = Location(title: value, latitude: jobLatitudeST[index], longitude: jobLongitudeST[index])
locations.append(location)
}
return locations
}
关于arrays - 无法快速加载类数组中的数组数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52013035/