我正在尝试在我的android应用程序中显示大风天气地图。我创建了一个html网页以将其加载到android webview中。加载网页后,尽管此脚本在PC Web浏览器上有效,但地图未显示。以下是html文件的代码
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<script src="https://unpkg.com/leaflet@0.7.7/dist/leaflet.js"></script>
<script src="https://api4.windy.com/assets/libBoot.js"></script>
<style>
#windy {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<p>This is map</p>
<div id="windy"></div>
<script>
const options = {
key: 'lq0BC9vwXFVfQqf26vLZYsUw1UU'
}
windyInit( options, windyAPI => {
// All the params are stored in windyAPI.store
const { overlays, broadcast } = windyAPI
var windMetric = overlays.wind.metric
// 'kt' .. actually selected metric for wind overlay
// Read only value! Do not modify.
overlays.wind.listMetrics()
// ['kt', 'bft', 'm/s', 'km/h', 'mph'] .. available metrics
overlays.wind.setMetric('bft')
// Metric for wind was changed to bft
broadcast.on('metricChanged', (overlay,newMetric) => {
// Any changes of any metric can be observed here
})
})
</script>
</body>
</html>
用于加载Webview的代码
webView.loadUrl("file:///android_asset/windy_radar.html")
webView.settings.javaScriptEnabled=true