【发布时间】:2017-10-10 15:48:22
【问题描述】:
我在理解 Swift 3 中的 Apple MapKit 时遇到了一些麻烦。
我在这里找到了一个例子:How to open maps App programmatically with coordinates in swift?
public func openMapForPlace(lat:Double = 0, long:Double = 0, placeName:String = "") {
let latitude: CLLocationDegrees = lat
let longitude: CLLocationDegrees = long
let regionDistance:CLLocationDistance = 100
let coordinates = CLLocationCoordinate2DMake(latitude, longitude)
let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
let options = [
MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
]
let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = placeName
mapItem.openInMaps(launchOptions: options)
}
除了在这种情况下我需要使用 address 而不是 coordinates 之外,这绝对有效。
我已经找到了使用谷歌地图执行此操作的方法,但我似乎无法找到 Apple Maps 的具体答案,如果它存在,我已经完成了对它的了解。
如果有人能帮助我理解正确的方法是什么,那就太棒了。我正在使用:
- Xcode 8.3.1
- 斯威夫特 3.1
- macOS
- 面向 iOS 10+
【问题讨论】:
标签: ios swift geolocation mapkit geocoding