2

How to open "google.navigation:q=" in android webview? This URL opens separate Google Maps app but I want it to appear inside my webview so that I can display other information below it.

I am using

In 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);

In 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);
    }

But it opens simple map app in webview where user has to manually enter the starting destination. I want it to get the current location of the user automatically and prompt for opening GPS if it is not already ON and launch turn by turn navigation in the webview itself.

Is this possible? Please guide.

1 Answers1

2

According Official Developer Guide for Request directions and launch Google Maps with the results adding &dir_action=navigate param:

  • 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.

should solve your issue, but seems now Google support turn by turn navigation only via Google Maps Application (I tried to start it even manually from phone browser, but without success). For more information take a look at this answer of xomena.

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
  • Did you solve this problem by click on Use The App in the Browser to open Google Maps? – BaDo Apr 25 '19 at 01:25