1引入链接
引入key值以及高德地图链接
https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css
https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js
https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值&plugin=AMap.Geocoder
2.地图初始化
代码如下(示例):
var map = new AMap.Map("container", { resizeEnable: true }); var geocoder = new AMap.Geocoder({ city: "02", //设置城市 radius: 1000 //范围 }); var marker = new AMap.Marker();
3.js代码
代码如下(示例):
function regeoCode() { var lnglat = document.getElementById('lnglat').value.split(','); map.add(marker); marker.setPosition(lnglat); geocoder.getAddress(lnglat, function(status, result) { if (status === 'complete'&&result.regeocode) { var address = result.regeocode.formattedAddress; document.getElementById('address').value = address; }else{ log.error('查询失败') } }); }