首页 > 解决方案 > 如何直接从应用程序打开 Apple 地图?

问题描述

我正在尝试使用此代码直接从应用程序打开苹果地图

let url =  "http://maps.apple.com/maps?saddr=&daddr=\(latString),\(longString)"             
UIApplication.shared.open(URL(string: "\(url)")!,options: [:],
completionHandler: nil)

但它首先打开' SAFARI ',然后移动到苹果地图。问题是,从地图我不能回到我的应用程序。顶部的后退按钮仅返回到 safari。

有没有办法直接打开苹果地图?还是我必须为此使用谷歌地图?

编辑:答案是正确的,但这是更好的答案

let mapsURL = URL(string: "maps://?saddr=\(latStringS),\(longStringS)&daddr=\(latStringD),\(longStringD)")!

this will show direction to destination from starting location

标签: swiftapple-maps

解决方案


通用解决方案

您应该将应用的深层链接作为 URL 传递以直接打开它们。这Maps是您要查找的 URL:

let mapsURL = URL(string: "maps://q?\(latString),\(longString)")!

具体功能

此外,地图还有一个特定功能,即:

class func openMaps(with mapItems: [MKMapItem], launchOptions: [String : Any]? = nil) -> Bool

您可以在文档中找到有关此的更多信息


具体框架

此外,您可以为此使用我的框架。支持 AppleMaps、GoogleMaps、Waze 和 Maps.Me。

你可以从这里得到它


推荐阅读