1. 程式人生 > >百度地圖API

百度地圖API

com element local del calc info 2.0 mat charset

<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> body, html,#allmap {width: 100%;height: 100%;overflow: hidden;hidden;margin:0;} </style> <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=4E11172e951f6014155d0fd482bcc57d"></script> <title>添加普通標註點</title> </head> <body> <div id="allmap"></div> </body> </html> <script type="text/javascript"> // 百度地圖API功能 /* var map = new BMap.Map("allmap"); var point = new BMap.Point(116.327151, 39.938546); map.centerAndZoom(point, 15); var marker = new BMap.Marker(point); // 創建標註 map.addOverlay(marker); // 將標註添加到地圖中 marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳動的動畫 */ var map = new BMap.Map("allmap"); var point = new BMap.Point(116.304, 39.965); map.centerAndZoom(point,12); var gc = new BMap.Geocoder(); map.enableScrollWheelZoom(); //啟用滾輪放大縮小 map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL})); //右上角,僅包含平移和縮放按鈕 var marker1 = new BMap.Marker(new BMap.Point(116.384, 39.925)); // 創建標註 map.addOverlay(marker1); // 將標註添加到地圖中 var label = new BMap.Label("拖動標註您的位置",{offset:new BMap.Size(20,-10)}); marker1.setLabel(label); map.addOverlay(marker1); marker1.enableDragging(); //可拖拽 //創建信息窗口 var infoWindow1 = new BMap.InfoWindow("拖動標註您的位置"); marker1.addEventListener("click", function(){this.openInfoWindow(infoWindow1);}); marker1.addEventListener("dragend", function(e){ var pt = e.point; gc.getLocation(pt, function(rs){ var addComp = rs.addressComponents; document.getElementById("localxy").value = e.point.lng + ", " + e.point.lat; document.getElementById("mt_10").innerHTML =addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber+‘&nbsp;<a class="dela" href="javascript:void(0)" onclick="showmap();">清除</a>‘; document.getElementById("localcontent").value =addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumbe; }); }); function showmap(){ document.getElementById("localcontent").value =""; document.getElementById("localxy").value = ""; $("#cn3").show(); $("#cn4").hide(); } </script>

百度地圖API