gpt4 book ai didi

android - 在 Android 应用程序中使用传单显示在线 map

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:00 24 4
gpt4 key购买 nike

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

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

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

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

关于android - 在 Android 应用程序中使用传单显示在线 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15946316/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com