javascript - 传单不显示 map

标签 javascript android html google-maps

我想在安卓设备上显示 map 。我看到变焦 Controller 和市场。但是 map 没有显示。

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

Image of the problem

Activity :

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>

我希望可以显示完整的 map

最佳答案

你能试试这个吗?

width: 100%;
height: auto;
}

关于javascript - 传单不显示 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58438514/

相关文章:

javascript - 使用 Javascript 更改 div 的背景图像

html - 用线条设计标题

javascript - 卡住表的标题行 asp.net

android - 在 Android 的 ImageView 中选择图像区域

javascript - Bluebird map 提前返回

android - Room 数据库中的 FOREIGN KEY 约束失败(代码 787)

android - 从 PreferenceScreen 到 DialogPreference

jquery - 用 jQuery 替换样式表

javascript - 仅检测伪元素上的点击事件

javascript - 模态框有覆盖不透明度