<div id="container" style=" height:600px; 100%; text-align: center;"></div>
<script src="https://webapi.amap.com/maps?v=1.4.15&key=你的高德key&plugin=AMap.PlaceSearch,AMap.AdvancedInfoWindow"></script>
var positions = [[116.397428, 39.90923]]; var map = new AMap.Map("container", { resizeEnable: true, center: positions[0], zoom: 13 }); var marker = new AMap.Marker({ position: map.getCenter(), icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png', offset: new AMap.Pixel(-13, -30), // 设置是否可以拖拽 draggable: false, cursor: 'move', // 设置拖拽效果 raiseOnDrag: true }); marker.setMap(map); var clickHandler = function(e) { marker.setMap(null); marker = new AMap.Marker({ position: e.lnglat, icon: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png', offset: new AMap.Pixel(-13, -30), // 设置是否可以拖拽 draggable: false, cursor: 'move', // 设置拖拽效果 raiseOnDrag: true }); marker.setMap(map); $('input[name=longitude]').val(e.lnglat.lng); $('input[name=latitude]').val(e.lnglat.lat); }; map.on('click', clickHandler);
效果: