关于 ios:Ionic – 在 Apple 地图应用中打开导航方向

Ionic - Open Navigation Directions in Apple Maps App

我有一个变量,即目的地,我需要使用 pin 打开本地 Apple 地图才能到达目的地。我已经尝试过这里回答的解决方案:Phonegap - Open Navigation Directions in Apple Maps App 但这不起作用。
如果我在测试时通过浏览器访问"maps://xx.xxxx,yy.yyyy",它会打开一个"不安全:/maps://xx.xxxx,yy.yyyy"。它不会固定地图,它永远不会将我指向我选择的目的地。我该如何解决这个问题?


我使用 LaunchNavigator cordova 插件来轻松实现这个期望的结果。与 Geo-Location cordova 插件配对时,这在 iOS 和 Windows Phone 上效果最佳。

要添加 LaunchNavigator 和 Geo-Location Cordova 插件:打开终端窗口,导航到项目目录的根目录并运行以下两个命令。

1
2
cordova plugin add cordova-plugin-geolocation
cordova plugin add uk.co.workingedge.phonegap.plugin.launchnavigator

之后,我通过将以下代码添加到我的项目中来实现映射到给定纬度/经度的功能。

1
2
var latitude = 39.7392, longitude = -104.9903;
launchnavigator.navigate([latitude, longitude]);

或者我通过将以下代码添加到我的项目来实现映射到地址字符串的功能。

1
2
var destination ="Denver, Colorado";
launchnavigator.navigate(destination);

我发现这是向移动应用程序的最终用户提供"点击查询路线"功能的最简单方法。对于 iOS、Android 和 Windows Phone 应用,这对我来说效果很好(代码没有变化)。


你可以尝试两件事

  • 将此行添加到您的 config.xml

  • 使用带有 _system 选项的 inAppBrowser 插件:

    var ref = window.open('maps://?q=xx.xxxx,yy.yyy', '_system');

  • 但是您应该检查地图应用程序的 url 方案
    https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html#//apple_ref/doc/uid/TP40007899-CH5-SW1

    如果你想要方向,你应该使用 daddr= 参数


    如果你有一个地址字符串,例如"纽约王子街 24 号":

    1
    2
    3
    $scope.launchDirections = function(address) {
       window.location.href="maps://maps.apple.com/?daddr=" + address;
    }

    如果你有经纬度,例如纬度:-33.8880165,经度:151.2310152:

    1
    2
    3
    $scope.launchDirections = function(lat, long) {
       window.location.href="maps://maps.apple.com/?q=" + lat +"," + long;
    }

    然后在你的 html 中调用它:

    1
    Show Directions