简体   繁体   English

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

[英]Phonegap - Open Navigation Directions in Apple Maps App

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. 我有两个变量 - 目标和源 - 并且,使用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方向作为webview,我无法返回到原始应用。

How can link be opened instead with the iOS default map application? 如何使用iOS默认地图应用程序打开链接?

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)

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。

In my case, changing from http://maps.apple.com/?q= to only maps:?q= not solving the problem. 在我的情况下,从http://maps.apple.com/?q=更改为仅maps:?q=无法解决问题。

The working scheme that open native Apple Maps with marker is as follows: 使用标记打开原生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. 使用iOS7.1模拟器进行测试,可能无法在以后的版本中使用。 I don't have the opportunity to test. 我没有机会参加考试。 Sorry. 抱歉。

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链接: 这里

The code 编码

I managed to get this working in 2018 on iOS 11.2 using the following format in iOS: 我在iOS 11中使用以下格式设法在iOS 11.2上使用它:

<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.xml file 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上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM