【发布时间】:2017-12-10 02:51:20
【问题描述】:
我正在尝试从我的地图上找到的任何注释中获取路线。我使用CloudKit 作为数据库来存储我所有的用户信息。注释使用CloudKit 中的location 索引来标出它们在地图上的位置。每次我运行我的代码时,注释都会返回为零,我如何让我的代码从注释中识别位置并从苹果地图返回方向?
@IBAction func getDirections(_ sender: Any) {
let view = MKPointAnnotation().coordinate
print("Annotation: \(String(describing: view ))")
let currentLocMapItem = MKMapItem.forCurrentLocation()
let selectedPlacemark = MKPlacemark(coordinate: view, addressDictionary: nil)
let selectedMapItem = MKMapItem(placemark: selectedPlacemark)
let mapItems = [selectedMapItem, currentLocMapItem]
let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
MKMapItem.openMaps(with: mapItems, launchOptions:launchOptions)
}
【问题讨论】:
-
你在做
let view = MKPointAnnotation().coordinate。那仍然没有意义。您正在创建一个空白注释,并获取它的坐标(但它没有)。您应该只获取您的坐标(来自 iCloud 或其他)并在创建MKMapItem时直接使用该坐标。 -
发现了!但现在并不是我的所有注释都会显示...stackoverflow.com/questions/47745464/…
标签: ios swift mapkit cloudkit mkannotation