ios - 使用 Apple Maps 转弯导航到注释

标签 ios swift3 ios10 apple-maps

我的 map 上有一个显示营业地点的注释和一个指示获取方向的按钮,我正在努力获取按钮来为我打开 Apple map ,其中包含指向注释位置的方向。这是我到目前为止完成的代码:

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)

关于ios - 使用 Apple Maps 转弯导航到注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39471810/

相关文章:

swift - 需要调整 NSJSONSerialization 到 iOS10

ios - 部署目标是什么意思?

ios - 如何在 ARKit 中找到真实世界表面的方向

ios - 更新到 Cocoapods 1.0 后错误太多

ios - 页面 View Controller 隐藏指示点并停在最后一页(无法返回)

ios - 如何以编程方式插入右键图像 UINavigationbar swift 3

ios - 如何在IOS 10的快速菜单项中启用小部件

ios - 如何为 `UILabel` 设置字符间距 (kern) 和删除线样式?

ios - UIButton 子类无法分配目标 - Swift 4

ios - 如何在 swift 3 中按下按钮时转到另一个 View Controller