【发布时间】:2016-01-24 14:28:58
【问题描述】:
我正在使用 google Places api 并使用坐标在苹果地图上添加注释。
我现在要做的是将坐标转换为名称和地址,并将其用于 Ekreminder。到目前为止,这是我的代码,但是当我尝试运行它时出现错误“致命错误:在展开可选值时意外发现 nil”:
addLocationReminderViewController.name = self.mapItemData.placemark.name
// Construct the address
let dic = self.mapItemData.placemark.addressDictionary as Dictionary!
let city = dic["City"] as! String
let state = dic["State"] as! String
let country = dic["Country"] as! String
addLocationReminderViewController.address = "\(city), \(state), \(country)"
}
编辑这是我获取信息的方式:
if data != nil{
let dic = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableLeaves) as! NSDictionary
let lat = dic["results"]?.valueForKey("geometry")?.valueForKey("location")?.valueForKey("lat")?.objectAtIndex(0) as! Double
let lon = dic["results"]?.valueForKey("geometry")?.valueForKey("location")?.valueForKey("lng")?.objectAtIndex(0) as! Double
let point = MKPointAnnotation()
point.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: lon)
point.title = self.resultsArray[indexPath.row]
let region = MKCoordinateRegion(center: point.coordinate, span: MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1))
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.mapView.setRegion(region, animated: true)
self.mapView.addAnnotation(point)
self.mapView.selectAnnotation(point, animated: true)
//
let placemark = MKPlacemark(coordinate: point.coordinate, addressDictionary: nil)
let mapItem = MKMapItem(placemark: placemark)
self.mapItemData = mapItem
//
})
【问题讨论】:
-
你的意思是
Dictionary!吗?
标签: swift mapkit coordinates eventkit