安卓的WebView无法显示谷歌地图。

4
如果我启动此应用程序,可以正确地看到Web视图,但它无法加载Google地图(https://maps.google.com/maps?q=43.0054446,-87.9678884&t=m&z=7),但它可以加载普通的Google页面(https://www.google.it/#q=43.0054446%2C-87.9678884)。为什么?有办法解决吗?
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,但当链接加载时,页面会全屏显示(即使我在WebView下面插入其他内容)。为什么?


4
我认为你需要修复WebViewSettings。例如,你肯定需要使用myWebView.getSettings().setJavaScriptEnabled(true); - Sherif elKhatib
我只需要从httpS中删除S。现在我又有了另一个问题。我更新了我的问题。 - As As
2个回答

4
我刚刚将httpS中的S去掉了,它可以正常工作。我不知道这是否有帮助。

3

对我来说,我漏掉了 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);

感谢评论者的添加,否则我就要疯了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接