Android的webview不显示谷歌地图

问题描述:

如果我启动这个应用程序,我可以正确地看到webview,但它不会加载谷歌地图(https://maps.google.com/maps?q=43.0054446,-87.9678884&t=m&z=7),但它会加载正常的谷歌页面(https://www.google.it/#q=43.0054446%2C-87.9678884)。为什么?有没有办法解决它?Android的webview不显示谷歌地图

public class MainActivity extends Activity 
    { 
     WebView myWebView; 
     String mapPath = "https://maps.google.com/maps"; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) 
     { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_main); 
      myWebView = (WebView)findViewById(R.id.mapview); 
      String map2="?q=43.0054446,-87.9678884&t=m&z=7"; 
      myWebView.loadUrl(mapPath+map2);  
     } 

     @Override 
     public boolean onCreateOptionsMenu(Menu menu) { 
      // Inflate the menu; this adds items to the action bar if it is present. 
      getMenuInflater().inflate(R.menu.main, menu); 
      return true; 
     } 
    } 

现在我有另一个问题。这是我的xml布局。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<RelativeLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 
<TextView 
     android:id="@+id/textview" 
     android:layout_height="@string/hello_world"/> 
</RelativeLayout> 

<RelativeLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 
<WebView 
     android:id="@+id/mapview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</RelativeLayout> 

我想显示在屏幕的上半部分的WebView,但链接加载时,页面全屏(即使我插入别的web视图下)。为什么?

+4

我认为你需要修复WebViewSettings。例如,你一定会需要'myWebView.getSettings()。setJavaScriptEnabled(true);' –

+0

我只是要从httpS中删除S.现在我有另一个问题。我更新了我的问题, –

我刚刚从httpS中删除了S,它起作用。我不知道这是否有帮助。

+0

你说得对!非常感谢。 +10 :) –

对我而言,我错过了myWebView.getSettings().setJavaScriptEnabled(true);

这是我的代码:

//set the webview and have open the map 
mywebview = (WebView) findViewById(R.id.webView); 
WebSettings webSettings = mywebview.getSettings(); 
webSettings.setBuiltInZoomControls(true); 
mywebview.getSettings().setJavaScriptEnabled(true); 

mywebview.setWebViewClient(new Callback()); 
mywebview.loadUrl(mapPath+map2); 

多亏了评论者补充说,我会一点点坚果。