swift - 如何直接从应用程序打开 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
解决方案
通用解决方案
您应该将应用的深层链接作为 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。
推荐阅读
- sql - 如何加入连接列 SQL
- mule - 有没有办法在 anypoint 平台上获取端点列表
- arrays - 如何使用每个项目 2 个部分访问数组中的不同元素
- c# - ASP.NET CORE 中的 CORS 策略已阻止访问 XMLHttpRequest
- html - 让 div 只打印在某个高度的方法?
- c# - 如何限制asp.net文本框中的最大和最小文本数?
- ssh - 如果通过 GitLab CI 完成 SSH 到远程服务器被拒绝
- java - GTK 中的自定义对话框不显示任何内容
- react-native - React-Native - 全局组件而不是使用 redux?
- c# - 如何使用 Azure Active Directory Graph Client 在 Azure B2C 中查找具有相同用户名\电子邮件地址的所有用户?