【问题标题】:How to open "google.navigation:q=<someLocation>" in android webview?如何在 android webview 中打开“google.navigation:q=<someLocation>”?
【发布时间】:2019-01-02 19:08:56
【问题描述】:

如何在 android webview 中打开“google.navigation:q=”?此 URL 会打开单独的 Google Maps 应用程序,但我希望它出现在我的 web 视图中,以便我可以在其下方显示其他信息。

我正在使用

在活动 1 中:

      String urlString="https://www.google" +
                    ".com/maps/dir/? 
      api=1&destination="+locations.get(position)
                    +"&travelmode=driving";
      Intent mapIntent = new Intent(view.getContext(), 
      NavigateActivity.class);
      mapIntent.putExtra("url", urlString); //Optional parameters               
      context.startActivity(mapIntent);

在活动 2 中:

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mapURL = extras.getString("url");
    }
    WebView webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new WebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);

    if (mapURL != null && !mapURL.isEmpty()) {

        webView.loadUrl(mapURL);
    }

但它会在 webview 中打开简单的地图应用程序,用户必须手动输入起始目的地。我希望它自动获取用户的当前位置并提示打开 GPS(如果它尚未打开)并在 web 视图本身中启动轮流导航。

这可能吗?请指导。

【问题讨论】:

  • 请查看更新后的答案。

标签: android google-maps webview navigation


【解决方案1】:

根据Request directions and launch Google Maps with the results 的官方开发者指南添加&amp;dir_action=navigate 参数:

  • dir_action=navigate(可选):根据具体情况启动到指定目的地的逐步导航或路线预览 来源是否可用。如果用户指定一个来源并且 离用户当前位置不近,或者用户当前位置不近 位置不可用,地图启动路线预览。如果用户 不指定原点(在这种情况下原点默认为 用户当前位置),或原点靠近用户当前位置 位置,地图将启动逐向导航。注意 导航并非在所有 Google 地图产品和/或两者之间都可用 所有目的地;在这些情况下,此参数将被忽略。

应该可以解决您的问题,但现在 Google 似乎仅通过 Google Maps Application 支持逐个导航(我什至尝试从手机浏览器手动启动它,但没有成功)。欲了解更多信息,请查看thisxomena 的答案。

【讨论】:

  • 您是否通过点击使用浏览器中的应用打开谷歌地图解决了这个问题?
猜你喜欢
  • 2018-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多