高德地图 点击取坐标经纬度
<style>.layui-form-select dl { max-height:200px; }html, body, #container {//container 为地图的容器height: 100%;width: 100%;}.amap-icon img,.amap-marker-c...
·
<style>
.layui-form-select dl { max-height:200px; }
html, body, #container { //container 为地图的容器
height: 100%;
width: 100%;
}
.amap-icon img,
.amap-marker-content img{
width: 25px;
height: 34px;
}
.marker {
position: absolute;
top: -20px;
right: -118px;
color: #fff;
padding: 4px 10px;
box-shadow: 1px 1px 1px rgba(10, 10, 10, .2);
white-space: nowrap;
font-size: 12px;
font-family: "";
background-color: #25A5F7;
border-radius: 3px;
}
.input-card{
width: 32rem;
z-index: 170;
}
.input-card .btn{
margin-right: .8rem;
}
.input-card .btn:last-child{
margin-right: 0;
}
</style>
<div id='container'></div> //地图容器
function addMark(){
var data = $("#dz").val(); //form 表单里原本的值
var oldjwd=data.split(",");
var gaodeMap = new AMap.Map('container', {
resizeEnable: true, //是否监控地图容器尺寸变化
zoom:11, //初始化地图层级
center: oldjwd //初始化地图中心点
});
marker = new AMap.Marker({
icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
position: oldjwd, //初始坐标
offset: new AMap.Pixel(-13, -30)
});
marker.setMap(gaodeMap);
gaodeMap.on('click', function(e) { //鼠标点击地图事件 将marker放在鼠标点击的位置
console.log(e)
var rclnglat=e.lnglat;
marker.setPosition(rclnglat);
$("#dz").val(rclnglat.lng+","+rclnglat.lat); //将选择的坐标放入input框
$(".layui-container").show(); //地图隐藏
$("#container").hide(); //存放经纬度的input显示
});
}更多推荐




所有评论(0)