Ios 使用Apple Maps逐个导航到注释
我的地图上有一个标注,显示了一个商业位置,还有一个按钮,上面写着“获取方向”,我正在努力让按钮为我打开苹果地图,上面有指向标注位置的方向。以下是我迄今为止完成的代码:Ios 使用Apple Maps逐个导航到注释,ios,swift3,ios10,apple-maps,Ios,Swift3,Ios10,Apple Maps,我的地图上有一个标注,显示了一个商业位置,还有一个按钮,上面写着“获取方向”,我正在努力让按钮为我打开苹果地图,上面有指向标注位置的方向。以下是我迄今为止完成的代码: import UIKit import MapKit class FourthViewController: UIViewController , MKMapViewDelegate { @IBOutlet weak var map: MKMapView! override func viewDidLoad
import UIKit
import MapKit
class FourthViewController: UIViewController , MKMapViewDelegate {
@IBOutlet weak var map: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
let latitude: CLLocationDegrees = 54.647115
let longitude: CLLocationDegrees = -6.659070
let lanDelta: CLLocationDegrees = 0.05
let lonDelta: CLLocationDegrees = 0.05
let span = MKCoordinateSpan(latitudeDelta: lanDelta, longitudeDelta: lonDelta)
let coordinates = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
let region = MKCoordinateRegion(center: coordinates, span: span)
map.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.title = "Pose Beauty Salon"
annotation.subtitle = "100 Moneyhaw Road"
annotation.coordinate = coordinates
map.addAnnotation(annotation)
}
@IBAction func mapType(_ sender: AnyObject) {
switch (sender.selectedSegmentIndex) {
case 0:
map.mapType = .standard
case 1:
map.mapType = .satellite
default: // or case 2
map.mapType = .hybrid
}
}
@IBAction func getDirections(_ sender: AnyObject) {
}
}
我还看到了当单击时显示更多信息(如企业名称、地址、电话号码和URL)的注释。是否也很难添加?这是我用来解决问题的代码:
let latitude: CLLocationDegrees = 54.647115
let longitude: CLLocationDegrees = -6.659070
let url = URL(string: "https://www.posebeautysalon.com")
let regionDistance:CLLocationDistance = 10000
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 = "Pose Beauty Salon"
mapItem.phoneNumber = "+442886737777"
mapItem.url = url
mapItem.openInMaps(launchOptions: options)