Ios 如何从struct获取纬度和经度并在mapbox Swift上显示

Ios 如何从struct获取纬度和经度并在mapbox Swift上显示,ios,swift,mapbox,swift4.2,Ios,Swift,Mapbox,Swift4.2,我从API中获取数据,我需要一个纬度和经度数组来显示地图上的所有位置(我使用Mapbox绘制地图) 位置的结构: struct Response : Decodable { let success : Bool let code : Int let message : [location] } struct location : Decodable{ let id : Int let name : String let img : String let latitude : String le

我从API中获取数据,我需要一个纬度和经度数组来显示地图上的所有位置(我使用Mapbox绘制地图)

位置的结构:

struct Response : Decodable {
let success : Bool
let code : Int
let message : [location]
}

struct location : Decodable{
let id : Int
let name : String
let img : String
let latitude : String
let longitude : String
let city : String
let country : String
let created_at : String
let updated_at : String
}


请帮我解决这个问题,我想在地图上显示分配情况

您可以像这样从地图中的数组设置位置

for locationStruct in self.locations
{
    let annotation = MGLPointAnnotation()
    annotation.coordinate = CLLocationCoordinate2D(latitude: Double(locationStruct.latitude), longitude: Double(locationStruct.longitude))
    annotation.title = locationStruct.name
    annotation.subtitle = "Your Subtitle"
    self.mapView.addAnnotation(annotation)

}

CLLocationCoordinate2D(纬度:Double(locationStruct.latitude),经度:Double(locationStruct.latitude))中给出错误“调用初始值设定项时没有精确匹配”
初始值设定项创建可选的。你必须处理它。永远不要使用信号量使异步网络请求变得同步。那是一种可怕的做法。
for locationStruct in self.locations
{
    let annotation = MGLPointAnnotation()
    annotation.coordinate = CLLocationCoordinate2D(latitude: Double(locationStruct.latitude), longitude: Double(locationStruct.longitude))
    annotation.title = locationStruct.name
    annotation.subtitle = "Your Subtitle"
    self.mapView.addAnnotation(annotation)

}