簡體   English   中英

使用 Apple Maps 逐次導航到注釋

[英]Turn by turn navigation to annotation with Apple Maps

我的地圖上有一個 Annotation,顯示了一個營業地點和一個按鈕,上面寫着獲取路線,我正在努力獲得按鈕來為我打開 Apple Maps,並提供到 Annotations 位置的路線。 這是我到目前為止所做的代碼:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM