【问题标题】:Leaftlet dont show the map传单不显示地图
【发布时间】:2020-02-14 17:20:29
【问题描述】:

我想在安卓设备上显示地图。我看到了变焦控制器和市场。但是地图不显示。

我遵循 leftlet 示例,如果我在 html 中传递我的代码,则地图会显示,但不会在 android 中显示。

Image of the problem

活动:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_map)
    Log.d("----->Map", "")
    // init webView

    // displaying content in WebView from html file that stored in assets folder
    webView = map_location
    //webView.clearCache(true)
    //webView.clearHistory()


    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("file:///android_asset/map.html");



}

HTML:

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <script src="./leaflet.js"></script>
    <link rel="stylesheet" href="./leaflet.css">


    <style>
    body {
    padding: 0;
    margin: 0;
    }
     html, body, #map {
        height: 100%;
        width: 100vw; }

    </style>


</head>
<body>
<div id="map"></div>
<script>

    var map = L.map('map').setView([41.66, -4.72], 10);

    L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
        maxZoom: 18,
        attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
            '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
            'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
        id: 'mapbox.streets'
    }).addTo(map);

    map.locate({setView: true, maxZoom: 16});

    //L.control.scale().addTo(map);
    L.marker([41.66, -4.71], {draggable: true}).addTo(map);


</script>

</body>
</html>

我希望可以显示完整的地图

【问题讨论】:

    标签: javascript android html google-maps


    【解决方案1】:

    你可以试试这个吗?

    width: 100%;
    height: auto;
    }
    

    【讨论】:

    • 实际上
      是显示但地图“街道名称..”不是。
    【解决方案2】:

    我发现问题出在哪里,我只是在测试传单库时创建了 webview,但是我忘记给应用程序授予互联网权限,这使得显示完整的地图

    【讨论】:

      猜你喜欢
      • 2021-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多