【问题标题】:PhoneGap direction using native Google Maps使用原生谷歌地图的PhoneGap方向
【发布时间】:2013-10-21 23:54:42
【问题描述】:

我有一个包含一个按钮的应用程序,该按钮应向用户显示前往当地商家的路线。我希望使用 Google 地图提供路线,其中包含用户当前位置的逐步道路路线。

我希望本地 Google 地图应用能够处理路线,但是当我尝试使用 hrefhttps://maps.google.com/maps?q=... 时,Google 地图会打开用户的网络浏览器,而不是在他们的 Google 地图应用中。

这个基于网络的地图没有提供我想要的逐步路线 - 它只提供从 A 点到 B 点的俯视图。

我也试过

<a href="geo:38.897096,-77.036545">businesname</a>

<a href="geo:someAddressHere">businessname</a>

这些hrefs确实启动了本地 Google 地图应用,但未显示分步方向。

总而言之:如何显示 Google 地图视图以提供分步指示(最好使用本机应用程序)。

【问题讨论】:

  • This 问题可能会有所帮助。

标签: android google-maps geolocation


【解决方案1】:

您要查找的内容称为intent。这是一个将一些信息传递给其他应用程序并可以启动它的命令。

我要做的是在您的代码中添加一个在用户触摸按钮时调用的方法。这种方法类似于:

//Pass the link to the itinerary you want
void launchGMaps(String link) {

    //Pass the link and the instruction to show something to an Intent
    Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(link));
    //Give the name of the app to start and the activity to start in this app.
    myIntent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
    //Gooooooooooo !
    startActivity(myIntent);
}

希望对你有所帮助。

F

【讨论】:

【解决方案2】:

如果您没有加载 inAppBrowser 插件,您可以这样做:

window.open("http://maps.google.com/maps?saddr=some+address&daddr=another+Address");

它将打开一个带有方向的新浏览器窗口(但不是本机应用程序)

或者您可以使用前面的答案 frouil,但要这样做,您必须执行以下操作。 在您的主 Java 文件中,在 super.loadUrl 调用之前添加:

appView.addJavascriptInterface(this, "YouActivityName");

然后从您的 javascript 中,您使用以下方法:

window.YouActivityName.launchGMaps("http://maps.google.com/maps?saddr=some+address&daddr=another+Address");

如果你省略了saddr部分,android会尝试使用你当前的位置和起始地址

【讨论】:

    【解决方案3】:

    您不需要任何插件。
    只需将此用于任何版本的 phonegap,但不要在 phonegap 3x 中使用 href。
    使用 window.open();

    对于导航 - window.open("google.navigation:q=23.3728831,85.3372199&mode=d" , '_system');

    对于搜索 - window.open("geo:0,0?q=pizza" , '_system');

    在这里阅读 - https://developers.google.com/maps/documentation/android/intents

    【讨论】:

      猜你喜欢
      • 2012-07-28
      • 2017-07-25
      • 2013-03-22
      • 1970-01-01
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 2020-02-20
      • 1970-01-01
      相关资源
      最近更新 更多