<%@page pageEncoding="utf-8"%>
<div class="widget model_widget">
<div class="widget-body">
<div id="horizontal-form">
<form class="form-horizontal" method="post" id="addElectricCard">
<div>
<div class="form-group">
<label class="col-sm-2 control-label no-padding-right">设备经度</label>
<div class="col-sm-9">
<input class="form-control" id="lng" name="number"
placeholder="经度" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label no-padding-right">设备纬度</label>
<div class="col-sm-9">
<input class="form-control" id="lat" name="number"
placeholder="纬度" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label no-padding-right">地图</label>
<div class="col-sm-9" style="height: 400px;">
<div id="container" style="height: 350px;" class="map"></div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript" src='http://webapi.amap.com/maps?v=1.4.0&key=key'></script>
<script type="text/javascript">
var map = new AMap.Map("container", {
resizeEnable: true
});
//为地图注册click事件获取鼠标点击出的经纬度坐标
map.on('click', function(e) {
document.getElementById("lat").value = e.lnglat.getLat();
document.getElementById('lng').value = e.lnglat.getLng();
});
</script>
以上是完整代码
需要注意的是,script 连接中的key值是需要自己获取的