【问题标题】:Problem: Loading Mapbox in Webview (Android Studio Project)问题:在 Webview 中加载 Mapbox(Android Studio 项目)
【发布时间】:2019-05-18 21:08:08
【问题描述】:

我的网站中有一个 html 文件: http://manizani.ir/hamyar_gas_php/map/map_app.html

我想在我的 Android 应用程序上显示它。我创建了一个 Activity 并使用 Webview 加载上面的 url。但是什么都没有加载,它只显示一个空活动。

我可以成功加载任何其他网页,但不能加载我的网址。

请帮我解决。

非常感谢

activity_map_web.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapWebActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <WebView
            android:id="@+id/webview_intro"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </WebView>

    </LinearLayout>

</RelativeLayout>

////////////文件结束////////////////

MapWebActivity.java:

public class MapWebActivity extends AppCompatActivity {

    WebView WV;
    String url = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map_web);

        try {

            WV = (WebView) findViewById(R.id.webview_intro);

            WV.getSettings().setLoadsImagesAutomatically(true);
            WV.getSettings().setJavaScriptEnabled(true);
            WV.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
            WV.getSettings().setBuiltInZoomControls(true);

            WV.getSettings().setDomStorageEnabled(true);
            WV.getSettings().setAppCacheEnabled(true);
            WV.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
            WV.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);

            WV.setWebViewClient(new WebViewClient());


                  url="http://manizani.ir/hamyar_gas_php/map/map_app.html";

                WV.loadUrl(url);


        } catch (Exception ex) {
            Toast.makeText(this, ex.toString(), Toast.LENGTH_SHORT).show();
        }
    }
}

【问题讨论】:

  • Mani,请添加代码和更多细节

标签: android webview android-webview


【解决方案1】:

Mapbox 使用 WebGL,您的设备可能不支持。 网页浏览日志:

 [INFO:CONSOLE(31)] "Error: Failed to initialize WebGL", source: https://api.mapbox.com/mapbox-gl-js/v2.2.0/mapbox-gl.js (31)

更多here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-07
    • 1970-01-01
    • 2011-07-17
    • 1970-01-01
    相关资源
    最近更新 更多