"?-6ren"> "?-如何在 android webview 中打开“google.navigation:q=”?此 URL 会打开单独的 Google Maps 应用程序,但我希望它出现在我的 WebView 中,以便我-6ren">
gpt4 book ai didi

android - 如何在android webview中打开 "google.navigation:q="?

转载 作者:行者123 更新时间:2023-11-29 23:22:28 25 4
gpt4 key购买 nike

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

我正在使用

在 Activity 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);

在 Activity 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 中打开简单的 map 应用程序,用户必须在其中手动输入起始目的地。我希望它自动获取用户的当前位置并提示打开 GPS(如果它尚未打开)并在 webview 本身中启动轮流导航。

这可能吗?请指导。

最佳答案

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

  • dir_action=navigate (optional): Launches either turn-by-turn navigation or route preview to the specified destination, based on whether the origin is available. If the user specifies an origin and it is not close to the user's current location, or the user's current location is unavailable, the map launches a route preview. If the user does not specify an origin (in which case the origin defaults to the user's current location), or the origin is close to the user's current location, the map launches turn-by-turn navigation. Note that navigation is not available on all Google Maps products and/or between all destinations; in those cases this parameter will be ignored.

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

关于android - 如何在android webview中打开 "google.navigation:q=<someLocation>"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54011877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com