MapBox Swift 3 api
Posted
技术标签:
【中文标题】MapBox Swift 3 api【英文标题】:MapBox swift 3 api 【发布时间】: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)
)
enter image description here
【问题讨论】:
请告诉我们您的坐标回复。 CLLocationCoordinate2DMake(location[1].doubleValue, location[0].doubleValue)(示例(41、28)) 添加终端截图 我要告诉你的是打印几何字典或位置数组的响应/输出。 怎么写格式""让坐标=CLLocationCoordinate2D(纬度:???,经度:???)坐标.append(坐标)"" 【参考方案1】:这是正确的答案
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)
【讨论】:
以上是关于MapBox Swift 3 api的主要内容,如果未能解决你的问题,请参考以下文章