<!doctype html>
<html>
<head>
<meta http-equiv=content-type content=text/html; charset=utf-8 />
<title>百度地圖</title>
<script type=text/javascript>
var iscreatr=false;
function initialize() {
var x = 116.4035;//設(shè)置默認(rèn)標(biāo)注點x
var y = 39.915;//設(shè)置默認(rèn)標(biāo)注點y
//---------------------------------------------基礎(chǔ)示例---------------------------------------------
var map = new bmap.map(allmap,{minzoom:12,maxzoom:20});// 創(chuàng)建map實例,將地圖掛到那個容器,用id表示
map.centerandzoom(new bmap.point(x,y),15); //初始化時,即可設(shè)置中心點和地圖縮放級別。
//map.centerandzoom(成都,13); // 初始化地圖,設(shè)置中心點坐標(biāo)和地圖級別。
map.enablescrollwheelzoom(true);//鼠標(biāo)滑動輪子可以滾動
var point = new bmap.point(x,y);//默認(rèn)
// 創(chuàng)建標(biāo)注對象并添加到地圖
var marker = new bmap.marker(point);
var label = new bmap.label(默認(rèn)提示,{offset:new bmap.size(20,-10)});
marker.setlabel(label)
map.addoverlay(marker);
marker.enabledragging(); //可拖拽
marker.addeventlistener(dragend, function(e){//將結(jié)果進(jìn)行拼接并顯示到對應(yīng)的容器內(nèi)
document.getelementbyid(r-result).innerhtml = e.point.lng + , + e.point.lat;//打印拖動結(jié)束坐標(biāo)
});
}
function loadscript() {
var script = document.createelement(script);
script.src = http://api.map.baidu.com/api?v=1.4&callback=initialize;
document.body.appendchild(script);
}
window.onload = loadscript;
</script>
</head>
<body>
<div id=r-result style=float:left;width:100px;>坐標(biāo)</div>
<div id=allmap style=width: 800px; height: 500px></div>
</body>
</html>