android - 如何在 WebView 中显示方向

标签 android google-maps webview

在我的应用程序中,我想使用 WebView 显示谷歌地图中两个地理点之间的方向。我试过了,但它没有显示方向,它只显示标志页。怎么做?

public class android_testing extends Activity {

public WebView webview;     
protected ProgressDialog web_pd;
final Handler rb_web_pd_Handler = new Handler();    

@Override
public void onCreate(Bundle icicle) 
{
    super.onCreate(icicle);                   
    setContentView(R.layout.main);        

    webview = (WebView)findViewById(R.id.wv_direction);  
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setPluginsEnabled(true);
    webview.getSettings().setDomStorageEnabled(true);
    webview.getSettings().setBuiltInZoomControls(true);
    webview.getSettings().setSupportZoom(true);
    webview.getSettings().setAllowFileAccess(true);

    web_pd = ProgressDialog.show(android_testing.this, "", "Please wait...", true);
    Thread t = new Thread() 
    {
        public void run() 
        {               
            rb_web_pd_Handler.post(checked_LoginResp);
        }                                               
    };
    t.start();

    webview.setWebViewClient(new WebViewClient() 
    {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
        {
            // Handle the error
        }

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith("tel:")) { 
                    Intent intent = new Intent(Intent.ACTION_DIAL,
                            Uri.parse(url)); 
                    startActivity(intent); 
            }else if(url.startsWith("http:") || url.startsWith("https:")) {
                view.loadUrl(url);
            }
            return true;
        }
    });
    float source_lat = 17.493133f;
    float source_long = 78.398438f;
    float dest_lat = 17.444992f;
    float dest_long = 78.379898f;
    String page_url ="http://maps.google.com/maps?daddr="+dest_lat+","+dest_long+"&saddr="+source_lat+","+source_long;             
    System.out.println("URL:"+page_url);       
    webview.loadUrl(page_url);      
}

 final Runnable checked_LoginResp = new Runnable()
 {
     public void run()
     {
         try
         {
             webview.setWebChromeClient(new WebChromeClient() 
             {
                 public void onProgressChanged(WebView view, int progress)
                 {
                     if(progress == 100)
                     {
                         web_pd.dismiss();  
                     }
                 }
             });
         } 
         catch(Exception e)
         {
             e.printStackTrace();
         }
     }      
 };          }

是这样显示的

it shows like this

但是我想直接显示方向页。可能吗? enter image description here

最佳答案

阅读这篇文章,它将向您介绍如何在 WebView 中显示 Google Map Directin

Google Map Derection in WebView

关于android - 如何在 WebView 中显示方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9426243/

相关文章:

android - 无法在 Android studio 中运行 hello world

html - polymer 谷歌地图元素不显示

javascript - 谷歌地图上突然报错 : TypeError: _. x is not a function

android - 如何使用 HitTestResult 在 Android WebView 中使用 Longclick 获取链接图像(而不是图像 URL)的链接 URL

cocoa - WebView 不运行 loadHTMLString 中给出的 JavaScript

java - 插件Android支持中的异常(exception)-元素的内容必须包含格式正确的字符数据或标记

java - 提醒/警报的最佳方式

android - 使用 URL 显示新 Activity ?

android - 动态用户界面主题

javascript - Vue3谷歌地图标记无法删除