标签:innerhtml asc pen javascrip script nav map 缩放 anim
<!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+‘ <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
标签:innerhtml asc pen javascrip script nav map 缩放 anim
原文地址:http://www.cnblogs.com/hfgb/p/4113140.html