javascript Phonegap - 在 Apple Maps App 中打开导航方向

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14503551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 21:48:48  来源:igfitidea点击:

Phonegap - Open Navigation Directions in Apple Maps App

javascriptjqueryioscordovamaps

提问by Ben

I have two variables - Destination and Source - and, using Phonegap, I'm trying to use jQuery to open the external iPhone Apple Maps app with directions.

我有两个变量 - Destination 和 Source - 并且,使用 Phonegap,我正在尝试使用 jQuery 打开带有方向的外部 iPhone Apple Maps 应用程序。

The code I'm using looks like this:

我正在使用的代码如下所示:

var url = 'http://maps.apple.com/?q=daddr='+destination+'&saddr='+source;
window.location = url;

Whenever I click the relevant button however, it opens a new view in-app with Google directions as a webview, and I cannot return to the original app.

但是,每当我单击相关按钮时,它都会在应用程序内打开一个新视图,其中包含 Google 路线作为网络视图,并且我无法返回到原始应用程序。

How can link be opened instead with the iOS default map application?

如何使用 iOS 默认地图应用程序打开链接?

回答by Ben

Changing http://maps.apple.com/?q=to just maps:did the trick.

更改http://maps.apple.com/?q=为就行maps:了。



NB: make sure you write maps:and not map:as, while the latter will run the correct app, it will crash immediately after opening (thanks jprofitt)

注意:确保你写maps:而不是map:as,虽然后者会运行正确的应用程序,但它会在打开后立即崩溃(感谢 jprofitt)

回答by Josh Buchea

Today I was able to open the native Apple Maps app with marker from a Cordova app using BOTH of the follow URL schemes:

今天,我能够使用以下两种 URL 方案从 Cordova 应用程序中打开带有标记的原生 Apple Maps 应用程序:

maps://maps.apple.com/?q={latitude},{longitude}

AND

maps://?q={latitude},{longitude}

In a link:

在一个链接中:

<a href="maps://maps.apple.com?q={latitude},{longitude}">
<!-- OR -->
<a href="maps://?q={latitude},{longitude}">

From JavaScript:

来自 JavaScript:

window.location.href = "maps://maps.apple.com/?q="+lat+","+lng;
// OR
window.location.href = "maps://?q="+lat+","+lng;

The app is running on an iOS device, iOS version 8.1.2, and cordova-ios is version 3.7.0.

该应用程序在 iOS 设备上运行,iOS 版本为 8.1.2,cordova-ios 为版本 3.7.0。

回答by Amir Fazwan

In my case, changing from http://maps.apple.com/?q=to only maps:?q=not solving the problem.

就我而言,从http://maps.apple.com/?q=改为 onlymaps:?q=不能解决问题。

The working scheme that open native Apple Maps with marker is as follows:

使用marker打开原生Apple Maps的工作方案如下:

maps://maps.apple.com/?q={latitude},{longitude}

full working code:

完整的工作代码:

window.location.href = "maps://maps.apple.com/?q="+lat+","+lng;

Tested working with iOS7.1 simulator, might not works in later version. I don't have the opportunity to test. Sorry.

使用 iOS7.1 模拟器测试过,在更高版本中可能无法使用。我没有机会测试。对不起。

Supported Apple Maps parameters can be found here: https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html

可以在此处找到支持的 Apple Maps 参数:https: //developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html

Credit goes to this SO link: Here

归功于此 SO 链接:这里

回答by Sam L

The code

代码

I managed to get this working in 2018 on iOS 11.2 using the following format in iOS:

我设法在 2018 年在 iOS 11.2 上使用以下格式在 iOS 上运行:

<a onclick="window.open('maps://?q=51.178847,-1.826160', '_system');">Open in Maps</a>

And this format on Android:

Android上的这种格式:

<a onclick="window.open('geo:0,0?q=51.178847,-1.826160', '_system');">Open in Maps</a>

Config permissions

配置权限

Additionally, don't forget to add permissions to your config.xmlfile like so:

此外,不要忘记为您的config.xml文件添加权限,如下所示:

<allow-intent href="maps:*" />

In my project the geo:intention had existed from the beginning so it took my a while to figure out why this was working on Android and not iOS.

在我的项目中,这个geo:意图从一开始就存在,所以我花了一段时间才弄清楚为什么这适用于 Android 而不是 iOS。