Xcode Swift 2.0使用JSON在Mkmapview上进行多注释
最近我尝试在一个mapview中放置多个注释,我使用JSON填充我的位置纬度和经度。如何链接JSON文件并在mapview上显示多个注释,我面临一些问题Xcode Swift 2.0使用JSON在Mkmapview上进行多注释,xcode,swift,annotations,location,mkmapview,Xcode,Swift,Annotations,Location,Mkmapview,最近我尝试在一个mapview中放置多个注释,我使用JSON填充我的位置纬度和经度。如何链接JSON文件并在mapview上显示多个注释,我面临一些问题 class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let map = MKMapView(frame: view.bounds) map.autoresizingMask = .Flex
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let map = MKMapView(frame: view.bounds)
map.autoresizingMask = .FlexibleWidth | .FlexibleHeight
view.addSubview(map)
var annotations = NSMutableArray()
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
let pointData = NSData(contentsOfFile: NSBundle.mainBundle().pathForResource("location", ofType: "geojson")!)
let points = NSJSONSerialization.JSONObjectWithData(pointData!,
options: nil,
error: nil) as NSDictionary
for point in points["features"] as NSArray {
let coordinate = (point["geometry"] as NSDictionary)["coordinates"] as NSArray
let lon = coordinate[0] as CLLocationDegrees
let lat = coordinate[1] as CLLocationDegrees
let a = MKPointAnnotation()
a.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: lon)
annotations.addObject(a)
}
dispatch_async(dispatch_get_main_queue()) {
map.addAnnotations(annotations)
map.showAnnotations(map.annotations, animated: false)
}
}
}
}可以为您的问题添加更多详细信息,以获取helplet points=NSJSONSerialization.JSONObjectWithData(pointData!,(在调用中显示错误参数)当我尝试在swift 2.0中输入时,会显示此错误