<input type="text" placeholder="请输入关键字进行搜索" id="tipinput">
<input type="text" readonly id="getLng" value="108.947179">
<input type="text" readonly id="getLat" value="34.269991">
<div id="container" style="width:800px; height:600px;">地图正在加载中,请稍后......</div>
<script src="http://webapi.amap.com/maps?v=1.3&key=c6922b496ade0007d4795385aa6d235a&callback=init&plugin=AMap.Autocomplete"></script>
xxxxxxxxxx
function init(){
//初始化地图对象,加载地图
var map = new AMap.Map("container", {
resizeEnable: true,
});
var auto = new AMap.Autocomplete({
input: "tipinput"
});
AMap.event.addListener(auto,"select",select);//监听,选记录时触发
function select(e) {
if (e.poi && e.poi.location) {
map.setZoom(15);
map.setCenter(e.poi.location);
}
}
var clickEventListener = map.on('click', function(e) {
var getLngs = e.lnglat.getLng();
var getLats = e.lnglat.getLat();
document.getElementById("getLng").value = getLngs;
document.getElementById("getLat").value = getLats;
map.clearMap();// 清除地图覆盖物
//添加点标记
new AMap.Marker({
map: map,
position: [getLngs,getLats],
icon: new AMap.Icon({
size: new AMap.Size(32,34), //图标大小
image: "http://webapi.amap.com/images/marker_sprite.png",
})
});
});
}