gpt4 book ai didi

swift - 使用 MKMapView 获取方向和路线

转载 作者:行者123 更新时间:2023-11-28 06:09:17 25 4
gpt4 key购买 nike

我一直在尝试在不使用 map 或谷歌地图应用程序的情况下使用 MKMapView 获取方向和路线。我想在我的应用程序中使用它来打开其他应用程序。有人可以帮忙吗?

这是我所拥有的,但我想更改它,以便我可以在我的应用程序上获取方向和路线。我有 Swift 4 和 Xcode 9!

//Getting direction of location
@objc func getDirections(){
if let selectedPin = selectedPin {
let mapItem = MKMapItem(placemark: selectedPin)
let launchOptions = [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving]
mapItem.openInMaps(launchOptions: launchOptions)
}
}


extension ViewController : MKMapViewDelegate {
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{
if annotation is MKUserLocation {
//return nil so map view draws "blue dot" for standard user location
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView?.pinTintColor = UIColor.red
pinView?.canShowCallout = true
let smallSquare = CGSize(width: 30, height: 30)
let button = UIButton(frame: CGRect(origin: CGPoint.zero, size: smallSquare))
button.setBackgroundImage(UIImage(named: "Car"), for: .normal)
button.addTarget(self, action: #selector(getDirections), for: .touchUpInside)

pinView?.leftCalloutAccessoryView = button
return pinView
}
}

最佳答案

I have been trying to get directions and routes with MKMapView without using Maps or google maps app. I want to use it in my app with opening up other apps. Can someone help?

您无法在应用内启动导航。您可以做的是在两点之间绘制一条路径,并获取距离或预计驾驶/步行时间等信息。

Distance between two points MapKit 中搜索,您会找到一堆结果。例如看看here , herethis swift 4 soultion

关于swift - 使用 MKMapView 获取方向和路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47213553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com