android - 使用android更改html代码的值
问题描述
我有一个应用程序,它通过使用以下 WebView 并从我的资产文件夹中读取 HTML 文件来显示地图,如下所示:
WebView myWebView = (WebView) findViewById(R.id.map);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("file:///android_asset/test.html");
HTML文件是:
<!DOCTYPE html>
<html>
<head>
<title>Quick Start - Leaflet</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js" integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg==" crossorigin=""></script>
</head>
<body>
<div id="mapid" style="width: 600px; height: 400px;"></div>
<script>
var mymap = L.map('mapid').setView([Lat_Coordinate, Lon_Coordinate], 13);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
attribution: 'Map data © <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(mymap);
L.marker([Lat_Coordinate, Lon_Coordinate]).addTo(mymap)
.bindPopup("<b>My Location</b>").openPopup();
L.circle([Lat_Coordinate, Lon_Coordinate], 5000, {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5
}).addTo(mymap);
var popup = L.popup();
</script>
</body>
</html>
现在,我有另一个代码使用谷歌服务来获取用户的Lat
坐标Lon
。我得到的坐标是通过使用谷歌服务:
Latitude_Coor = location.getLatitude();
Longitude_Coor = location.getLongitude();
现在,一旦我在我的 java 代码中获得了它们,我想将它们作为值插入到HTML
上面的代码中[Lat_Coordinate, Lon_Coordinate]
。
如何将变量传递给我assets
文件夹中的 HTML?
谢谢!
解决方案
推荐阅读
- c# - 无法从 Azure KeyVault 读取值。指定的用户没有有效的个人资料
- spring - Spring & Reactor:使用来自 repo 的 Flux 订阅两个参数的二进制函数
- excel - 如果在单元格日期的 3 天内更改单元格的单元格颜色
- android - Wire 是否具有等效于 io.grpc.Metadata 和 MetadataUtils 的功能,用于将标头动态附加到调用?
- xaml - 在 Avalonia 中设置窗口图标
- c++ - VSCode 找不到包,但 CLion 可以(CMake)
- html - 背景图像缩放到 html 文档高度
- azure - dbutils.fs.mv 不断删除目录中的文件
- oracle - Oracle 序列生成器中的保留编号
- javascript - 如何将此 Angular 多边形 js 文件用作 HTML 元素?