2

我有一个包含一个按钮的应用程序,该按钮应该向用户提供前往当地企业的路线。我希望使用谷歌地图提供方向,其中包括用户当前位置的逐步道路方向。

我希望原生谷歌地图应用程序能够处理方向,但是当我尝试打开用户的网络浏览器hrefhttps://maps.google.com/maps?q=...,谷歌地图,而不是在他们的谷歌地图应用程序中。

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

我也试过

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

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

这些hrefs确实启动了本地 Google Maps 应用程序,但没有显示逐步的方向。

总结:如何显示谷歌地图视图以提供逐步指导(最好使用本机应用程序)。

4

3 回答 3

1

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

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

//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

于 2014-02-07T13:32:26.933 回答
1

如果您没有加载 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 会尝试使用你当前的位置和起始地址

于 2014-02-13T14:58:37.303 回答
0

你不需要任何插件。
只需将此用于任何版本的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

于 2015-07-21T10:43:43.353 回答