gpt4 book ai didi

ios - 在屏幕加载时启动 map 功能。 iOS, swift

转载 作者:行者123 更新时间:2023-11-29 11:42:42 25 4
gpt4 key购买 nike

我正在尝试在屏幕加载时自动启动 map 。

这能做到吗?在 View 上启动此功能确实出现了。

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {

if let anno = view.annotation {
let place = MKPlacemark(coordinate: anno.coordinate)
let destination = MKMapItem(placemark: place)
destination.name = "Vehicle Sighting"
let regionDistance: CLLocationDistance = 1000
let regionSpan = MKCoordinateRegionMakeWithDistance(anno.coordinate, regionDistance, regionDistance)

let options = [MKLaunchOptionsMapCenterKey: NSValue (mkCoordinate: regionSpan.center), MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span), MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving] as [String : Any]

MKMapItem.openMaps(with: [destination], launchOptions: options)
}
}

最佳答案

试试这个功能,你只需要传递坐标和地名,这个有效,我在几个项目中使用这个

static func openMapsAppWithLocation(coordinates:CLLocationCoordinate2D,placeName:String)
{
let regionDistance:CLLocationDistance = 10000
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 = placeName
mapItem.openInMaps(launchOptions: options)
}

希望对你有帮助

关于ios - 在屏幕加载时启动 map 功能。 iOS, swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45579272/

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