如何直接从应用程序打开Apple Maps?

问题描述

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

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

但是它先打开' SAFARI ',然后移动到苹果地图。问题是,我无法从地图上返回到我的应用。顶部后退按钮只能返回到野生动物园。

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

解决方法

常规解决方案

您应将应用程序的深层链接作为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。

You can get it from here