使用 Apple Maps 逐步导航到注释
Posted
技术标签:
【中文标题】使用 Apple Maps 逐步导航到注释【英文标题】:Turn by turn navigation to annotation with 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,这也很难添加吗?
【问题讨论】:
【参考方案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)
【讨论】:
以上是关于使用 Apple Maps 逐步导航到注释的主要内容,如果未能解决你的问题,请参考以下文章
通过使用纬度和经度的导航调用 maps.app(Apple 地图)
使用 Swift 3 在 iOS 10 中将图像从服务器加载到 Apple Map 中的注释视图