<!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" />
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=yourkey">
</script>
<title>定位</title>
<style type="text/css">
body, html, #allmap
{
100%;
height: 100%;
overflow: hidden;
margin: 0;
},
.anchorBL{ //去Logo
display:none;
}
</style>
</head>
<body>
<div id="allmap">
</div>
</body>
</html>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="querystring.js"></script>
<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(jd, wd); //根据经纬度定位
//doLocate(121.399696, 31.045601);
}
loadFunc();
</script>
From:http://www.cnblogs.com/xuejianxiyang/p/5282551.html