<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<title>Document</title>
<style>
html,
body {
padding: 0;
margin: 0;
height: 100%;
}
#container {
width: 100%;
height: 100%;
}
.toolbar {
position: absolute;
left: 0;
top: 26px;
z-index: 99;
}
</style>
<script type="text/javascript"
src="https://webapi.amap.com/maps?v=1.4.15&key=a8daa4fcd4baa46ce1128c3a79f6e29b&plugin=AMap.Geocoder"></script>
</head>
<body>
<div id="container"></div>
<div class="toolbar">
<input id='address' type="text" value='请输入地址'>
<button id="geo">button</button>
<input id='lnglat' disabled type="text">
</div>
<script type="text/javascript">
//地图加载
var map = new AMap.Map("container", {
resizeEnable: true
});
var geocoder = new AMap.Geocoder({
city: "310", //城市设为上海,默认:“全国”
});
var marker = new AMap.Marker();
document.getElementById("geo").onclick = geoCode;
function geoCode () {
var address = document.getElementById('address').value;
geocoder.getLocation(address, function (status, result) {
if (status === 'complete' && result.geocodes.length) {
var lnglat = result.geocodes[0].location
document.getElementById('lnglat').value = lnglat;
marker.setPosition(lnglat);
// map.add(marker);
map.setFitView(marker);
} else {
log.error('根据地址查询位置失败');
}
});
}
</script>
</body>
</html>
地图搜索定位
于 2022-04-19 09:49:41 首次发布
1972

被折叠的 条评论
为什么被折叠?



