gpt4 book ai didi

ios - MapBox swift 3 API

转载 作者:行者123 更新时间:2023-11-30 13:02:58 26 4
gpt4 key购买 nike

我使用 MapBox api swift 2.3 并读取 geojson。但是 swift 3 不行之后就开始升级了。

Swift 2.3 示例;它的工作

 for location in locations {
nate2D(latitude: location[1].doubleValue, longitude: location[0].doubleValue)

coordinates.append(coordinate)
}

Swift 3.0 不起作用

if let feature = feature as? NSDictionary {
if let geometry = feature["geometry"] as? NSDictionary {
if geometry["type"] as? String == "Polygon" {
var coordinates: [CLLocationCoordinate2D] = []
if let locations = geometry["coordinates"] as? NSArray {
for location in locations {
for i in (0 ..< (location as AnyObject).count)
{
let coordinate = CLLocationCoordinate2D(latitude: ???, longitude: ???)
coordinates.append(coordinate)
}
}
}

let shape = MGLPolygon(coordinates: &coordinates, count: UInt(coordinates.count))

DispatchQueue.main.async(execute: {
[unowned self] in
self.mapView.addAnnotation(shape)
})
}
}
}

enter image description here

最佳答案

这是正确答案

       for location in locations {


for i in (0 ..< (location as AnyObject).count)
{

let a = locations[0] as? NSArray

let b = a?[i] as? NSArray
var c = b?[0]
print(c);
let coordinate = CLLocationCoordinate2D(latitude: b?[1] as! CLLocationDegrees, longitude: b?[0] as! CLLocationDegrees)

coordinates.append(coordinate)

}


}

关于ios - MapBox swift 3 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39717394/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com