【问题标题】:How to open Apple Maps directly from app?如何直接从应用程序打开 Apple 地图?
【发布时间】:2021-01-08 13:31:40
【问题描述】:

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

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

【问题讨论】:

标签: swift apple-maps


【解决方案1】:

一般解决方案

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-19
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 2019-03-27
    相关资源
    最近更新 更多