百度api的使用

来源:互联网 发布:个人信息数据买卖qq群 编辑:程序博客网 时间:2024/05/20 12:46
<!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 {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}        #allmap{width:100%;height:500px;}        p{margin-left:5px; font-size:14px;}    </style>    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=m5OhArNG9qxL8sFRUceqCsnRnktYknGQ"></script>    <title>添加复杂内容的信息窗口</title></head><body><div id="allmap"></div></body></html><script type="text/javascript">    // 百度地图API功能    var sContent =        "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>服务热线</h4>" +        "<img style='float:right;margin:4px' id='imgDemo' src='2.jpg' width='139' height='104' title='天安门'/>" +        "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>010-58405785</p>" +        "</div>";    var map = new BMap.Map("allmap");    var point = new BMap.Point(116.306406,40.049256);    var marker = new BMap.Marker(point);    var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象    map.centerAndZoom(point, 25);    map.addOverlay(marker);    marker.addEventListener("click", function(){        this.openInfoWindow(infoWindow);        //图片加载完毕重绘infowindow        document.getElementById('imgDemo').onload = function (){            infoWindow.redraw();   //防止在网速较慢,图片未加载时,生成的信息框高度比图片的总高度小,导致图片部分被隐藏        }    });</script>

 

原创粉丝点击