【问题标题】:Turn by turn navigation to annotation with Apple Maps使用 Apple Maps 逐步导航到注释
【发布时间】:2016-09-13 13:51:19
【问题描述】:

我的地图上有一个注释显示一个营业地点和一个显示获取路线的按钮,我正在努力获取为我打开 Apple 地图的按钮,其中包含到注释位置的路线。这是我到目前为止所做的代码:

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,这也很难添加吗?

【问题讨论】:

    标签: ios swift3 ios10 apple-maps


    【解决方案1】:

    这是我用来解决问题的代码:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 2018-09-25
      • 1970-01-01
      • 2014-02-09
      相关资源
      最近更新 更多