【发布时间】:2016-09-27 06:22:43
【问题描述】:
我使用 MapBox api swift 2.3 并阅读 geojson。但是swift 3 dont work之后就开始升级了。
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)
})
}
}
}
【问题讨论】:
-
请告诉我们您的坐标回复。
-
CLLocationCoordinate2DMake(location[1].doubleValue, location[0].doubleValue)(示例(41、28))
-
添加终端截图
-
我要告诉你的是打印几何字典或位置数组的响应/输出。
-
怎么写格式""让坐标=CLLocationCoordinate2D(纬度:???,经度:???)坐标.append(坐标)""