如何直接从应用程序打开 Apple 地图?
How to open Apple Maps directly from app?
我正在尝试使用此代码直接从应用程序打开苹果地图
let url = "http://maps.apple.com/maps?saddr=&daddr=\(latString),\(longString)"
UIApplication.shared.open(URL(string: "\(url)")!,options: [:],
completionHandler: nil)
但它首先打开“SAFARI”,然后移动到苹果 maps.The 问题是,我无法从地图返回到我的应用程序。顶部的后退按钮只能返回到 safari。
有没有办法直接打开苹果地图?还是我必须为此使用 google 地图?
编辑 : 答案是正确的,但这里是更好的答案
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
您可以在 the documentation
中找到更多相关信息
具体框架
此外,您可以为此使用我的框架。支持 AppleMaps、GoogleMaps、Waze 和 Maps.Me.
我正在尝试使用此代码直接从应用程序打开苹果地图
let url = "http://maps.apple.com/maps?saddr=&daddr=\(latString),\(longString)"
UIApplication.shared.open(URL(string: "\(url)")!,options: [:],
completionHandler: nil)
但它首先打开“SAFARI”,然后移动到苹果 maps.The 问题是,我无法从地图返回到我的应用程序。顶部的后退按钮只能返回到 safari。
有没有办法直接打开苹果地图?还是我必须为此使用 google 地图?
编辑 : 答案是正确的,但这里是更好的答案
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
您可以在 the documentation
中找到更多相关信息具体框架
此外,您可以为此使用我的框架。支持 AppleMaps、GoogleMaps、Waze 和 Maps.Me.