在 android 应用程序中使用传单显示在线地图 [英] Use leaflet in an android application to show online map

查看:35
本文介绍了在 android 应用程序中使用传单显示在线地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

is there any samples project who shows how to use leaflet properly to show an online map in an android application. Because I tried many samples but every time i have an empty webview in my application. this is my code:

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 对象:

and this is the HTML object:

<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.

Seems to me that it's not working because you haven't enabled Javascript.

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

这篇关于在 android 应用程序中使用传单显示在线地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆