android - 在 Android 应用程序中使用传单显示在线 map

标签 android android-webview leaflet

是否有任何示例项目展示了如何正确使用传单在 Android 应用程序中显示在线 map 。因为我尝试了很多示例,但每次我的应用程序中都有一个空的 webview。 这是我的代码:

private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mWebView= (WebView)findViewById(R.id.map);
    mWebView.setWebChromeClient(new WebChromeClient());
    mWebView.loadUrl("file:///android_asset/www/map.html");

}

这是 HTML 对象:

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" href="css/leaflet-0.5.css" />
    <script>L_PREFER_CANVAS = true;</script>
    <script type="text/javascript" charset="utf-8" src="js/leaflet-src-0.5.js"></script>            
    <style>
        body {
            padding: 0;
            margin: 0;
        }
        html, body, #map {
            height: 100%;
        }
    </style>
</head>
<body>
    <div id="map"></div>

    <script>

        var map = L.map('map');

        L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', {
            attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
            maxZoom: 18
        }).addTo(map);
        map.locate({setView: true, maxZoom: 16});
        function onLocationFound(e) {
            var radius = e.accuracy / 2;

            L.marker(e.latlng).addTo(map)
            .bindPopup("You are within " + radius + " meters from this point").openPopup();

            L.circle(e.latlng, radius).addTo(map);
        }

        map.on('locationfound', onLocationFound);
        function onLocationError(e) {
            alert(e.message);
        }

        map.on('locationerror', onLocationError);




    </script>
</body>

最佳答案

在我看来它不起作用,因为您还没有启用 Javascript。

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);

关于android - 在 Android 应用程序中使用传单显示在线 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15946316/

相关文章:

Android FragmentTransaction 提交已调用

用于 Jenkins 的 Android Studio : How to create build. gradle 文件?

android - 使用 Phonegap 在 android 上捕获后使用 FileReader 读取视频文件

android - 我如何为我的 Android 应用程序实现像 "auto-hide navigation"这样的 chrome?

android - 如果 "display:none",文件选择器对话框不会在 android webview 中打开

map - 在 phonegap 应用程序中制作离线传单 map ?

android - 超链接获取 AndroidRuntimeException

javascript - 给定中心和正方形宽度的传单正方形

javascript - leaflet:根据哪个层处于事件状态切换标签

javascript - 找不到 webview javascript 接口(interface)函数