在android应用程序中使用传单显示在线地图
是否有任何示例项目展示了如何正确使用传单在android应用程序中显示在线地图。因为我尝试了很多示例,但每次我的应用程序中都有一个空的webview。 这是我的代码:在android应用程序中使用传单显示在线地图,android,android-webview,leaflet,Android,Android Webview,Leaflet,是否有任何示例项目展示了如何正确使用传单在android应用程序中显示在线地图。因为我尝试了很多示例,但每次我的应用程序中都有一个空的webview。 这是我的代码: private WebView mWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_
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 © <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>
L_preference_CANVAS=true;
身体{
填充:0;
保证金:0;
}
html,body,#map{
身高:100%;
}
var map=L.map('map');
L.tileLayer('http://{s}.tile.cloudmake.com/bc9a493b41014caab98f0471d759707/997/256/{z}/{x}/{y}.png'{
属性:“地图数据©;贡献者,图像©”,
最大缩放:18
}).addTo(地图);
locate({setView:true,maxZoom:16});
函数onLocationFound(e){
var半径=e.精度/2;
L.标记(e.latlng).添加到(地图)
.bindPopup(“您在距离此点“+半径+”米范围内”).openPopup();
L.圆(e.板条,半径)。添加到(地图);
}
地图上('locationfound',onLocationFound);
函数onLocationError(e){
警报(e.message);
}
map.on('locationerror',onLocationError);
在我看来,它不起作用,因为您没有启用Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
活跃
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("file:///android_asset/www/index.html");
}
In.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([51.505, -0.09], 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([51.5, -0.09]).addTo(mymap)
.bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup();
L.circle([51.508, -0.11], 500, {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5
}).addTo(mymap).bindPopup("I am a circle.");
L.polygon([
[51.509, -0.08],
[51.503, -0.06],
[51.51, -0.047]
]).addTo(mymap).bindPopup("I am a polygon.");
var popup = L.popup();
function onMapClick(e) {
popup
.setLatLng(e.latlng)
.setContent("You clicked the map at " + e.latlng.toString())
.openOn(mymap);
}
mymap.on('click', onMapClick);
</script>
</body>
</html>
快速入门-单张
var mymap=L.map('mapid').setView([51.505,-0.09],13);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyj1ijoibwwwwym94iiwiysi6imnpejy4nxvycta2emycxbdhrqcmz3n3gifq.rjfig214ariislb6b5aw'{
maxZoom:18,
属性:“映射数据©;贡献者”+
', ' +
“图像”,
id:“地图盒。街道”
}).addTo(mymap);
L.标记([51.5,-0.09])。添加到(mymap)
.bindPopup(“你好,世界!
我是一个弹出窗口。”).openPopup();
L.圆圈([51.508,-0.11],500{
颜色:“红色”,
填充颜色:“#f03”,
填充不透明度:0.5
}).addTo(mymap).bindPopup(“我是一个圆圈”);
L.多边形([
[51.509, -0.08],
[51.503, -0.06],
[51.51, -0.047]
]).addTo(mymap).bindPopup(“我是一个多边形”);
var popup=L.popup();
函数onMapClick(e){
弹出窗口
.setLatLng(即latlng)
.setContent(“您在“+e.latlng.toString()处单击了地图”)
.openOn(mymap);
}
mymap.on('click',onmaclick);
试试这个,android编译器4.4x(eclipse)
你到底试过什么?一个简单的网络视图,加载一个包含传单地图的html对象。他们有一个移动示例,它能工作吗?如果你想要一个有用的答案,你必须发布你的代码。这有点旧,但api密钥(BC9A493B41014CAAB98F0471D759707)正确吗?@Andy95,请检查我编辑的html页面,确保你的移动数据已启用,或者只需下载.js和.css文件并放在同一目录中。谢谢你
import android.webkit.WebView; //(dont forget to put WebView from Graphical layout palette or write manually inside layout folder activity_main.xml
private WebView tampilWeb; //(this is variable declaration)
// any function here ...
tampilWeb = (WebView)findViewById(R.id.webView1);
tampilWeb.getSettings().setJavaScriptEnabled(true);
tampilWeb.setWebViewClient(new WebViewClient());
tampilWeb.loadUrl("https://www.openstreetmap.org/#");