【问题标题】:Ionic - Open Navigation Directions in Apple Maps AppIonic - 在 Apple 地图应用中打开导航方向
【发布时间】:2015-03-24 17:28:57
【问题描述】:

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

【问题讨论】:

    标签: ios cordova maps ionic-framework apple-maps


    【解决方案1】:

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

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

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

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

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

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

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

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

    【讨论】:

    • 我不断收到错误消息。 errorplugin_not_installed 我确实按顺序安装了插件并安装了 npm。甚至尝试了离子状态重置——插件(重新安装所有插件)但没有去
    【解决方案2】:

    你可以尝试两件事

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

      <access origin="maps:*" launch-external="yes" />

    2. 使用带有 _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= 参数

    【讨论】:

    • 答案在 2016 年 6 月仍然有效,iOs 9.3 :-)。谢谢。
    【解决方案3】:

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

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

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

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

    然后在你的 html 中调用它:

    <div ng-click="launchDirections(address)">Show Directions</div>
    

    【讨论】:

      猜你喜欢
      • 2013-01-08
      • 1970-01-01
      • 2021-03-31
      • 1970-01-01
      • 2018-09-25
      • 2020-02-26
      • 2019-12-25
      • 1970-01-01
      • 2015-04-12
      相关资源
      最近更新 更多