百度地图添加带数字标注

时间:2024-01-30 17:49:02
<!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=79DXx96ybA2qLTZ9v1iqCZhX123"></script>
    <title>带文字标签的覆盖物</title>
</head>
<body>
    <div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
var value = (prompt("请输入数字,10000以内")+"") || "2222";
    // 百度地图API功能
    var map = new BMap.Map("allmap");
    var point = new BMap.Point(116.400244,39.92556);
    map.centerAndZoom(point, 12);
    var marker = new BMap.Marker(point);  // 创建标注
    map.addOverlay(marker);              // 将标注添加到地图中
  
  marker.setIcon(new BMap.Icon(\'http://map.baidu.com/newmap/static/common/images/mk_14e51b4.gif\',new BMap.Size(34,24),{
    imageOffset:new BMap.Size(0,(value.length-1)*-30) 
  }))

    var label = new BMap.Label(value,{offset:new BMap.Size(3,0)});
  label.setStyle({
    background:\'none\',color:\'#fff\',border:\'none\'
  });
    marker.setLabel(label);
</script>