Android - как открыть URL для вставки с помощью веб-просмотра - PullRequest
0 голосов
/ 29 февраля 2012

В моем приложении я хочу отобразить направления между двумя географическими точками, используя встроенный URL-адрес карт Google в веб-представлении. Но это не работает. В браузере отображается страница с указаниями, а в устройстве - страница с надписью.

Code:

открытый класс android_testing расширяет активность {

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) {

                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+"&output=embed";             
    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();
         }
     }      
 };          }

В браузере

enter image description here

Но в устройстве

enter image description here

1 Ответ

0 голосов
/ 29 февраля 2012

Чтобы просто отобразить карту Google с 2 местоположениями, не нужно использовать отдельную активность и веб-просмотр, просто позвоните, как показано ниже:

float source_lat = 17.493133f;
    float source_long = 78.398438f;
    float dest_lat = 17.444992f;
    float dest_long = 78.379898f;

String sourcelatitudeString=source_lat.toString();
String sourcelongitudeString=source_long.toString();


Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr="+sourcelatitudeString+","+sourcelongitudeString+"&daddr="+dest_lat+","+dest_long+""));
startActivity(intent);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...