<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"></script>
<title>拖拽地图</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
// 百度地图API功能
var map = new BMap.Map("allmap");
// 创建Map实例
map.enableScrollWheelZoom();
//启用滚轮放大缩小
//map.centerAndZoom(new BMap.Point(121.399696, 31.045601), 15);
function doLocate(jd, wd) {//根据经纬度定位
var point = new BMap.Point(jd, wd);
var marker = new BMap.Marker(point);
map.addOverlay(marker);
// map.addOverlay(new BMap.Marker(point));
marker.enableDragging(); //启用标注拖动
marker.addEventListener('dragend', function (e) {//拖动标注结束
var pointNew = e.point;
console.log(pointNew);
alert(pointNew.lng+'|'+pointNew.lat);
});
map.centerAndZoom(point, 15);
// 初始化地图,设置中心点坐标和地图级别。
}
function loadFunc() {
//var jd = QueryString["jd"];
//var wd = QueryString["wd"];
//alert(jd+'|'+wd);
doLocate(121.399696, 31.045601); //根据经纬度定位
//doLocate(121.399696, 31.045601);
}
loadFunc();
</script>