美文网首页
腾讯地图的地点标注

腾讯地图的地点标注

作者: 遇见sh | 来源:发表于2020-11-16 15:32 被阅读0次

    一、效果图


    image.png

    二、代码

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>为多个Marker添加事件</title>
    <style type="text/css">
    html,body{
        width:100%;
        height:100%;
    }
    #container{
        width:100%;
        height:100%;
    }
    *{
        margin:0px;
        padding:0px;
    }
    body, button, input, select, textarea {
        font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
    }
    .aa{
        text-align:center;white-space:nowrap;margin:10px;
    }
    </style>
    <script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
    <script>
    function init() {
        var point = new qq.maps.LatLng(34.666937,117.077718);
        var map = new qq.maps.Map(document.getElementById("container"), {
            point: point,
            zoom: 4
        });
        var infoWin = new qq.maps.InfoWindow({
            map: map
        });
     
        var markerArr = [
           {
               title: "济南", content: "姓名:宋* <br/>手机:400****669 <br/> 地址:山东济南"
           },
           {
               title: "天津", content: "姓名:宋* <br/>手机:400****669  <br/> 地址:天津"
           },
           {
               title: "北京", content: "姓名:宋* <br/>手机:400****669  <br/> 地址:北京市朝阳区朝外雅宝里2号楼一层F1—89"
           },
        ];
    
       var latlngs = [
            new qq.maps.LatLng(34.666937,117.077718),
            new qq.maps.LatLng(36.322246,116.195907),
            new qq.maps.LatLng(39.90884,116.41306)
        ];
    
     
    
        for(var i = 0;i < latlngs.length; i++) {
    
            (function(n){
                console.log("latlngs",latlngs)  
                var marker = new qq.maps.Marker({
                    position: latlngs[n],
                    map: map
                });
    
                var json = markerArr[i];
                qq.maps.event.addListener(marker, 'click', function() {
                    infoWin.open();
                    infoWin.setContent("<b class='iw_poi_title' title='" + json.title + "'>" + json.title + "</b><div class='iw_poi_content'>"+json.content+"</div>");
                    infoWin.setPosition(latlngs[n]);
                });
            })(i);
        }
    
    
    }
    </script>
    </head>
    <body onload="init();">
    <div id="container"></div>
    </body>
    </html>
    
    
    

    相关文章

      网友评论

          本文标题:腾讯地图的地点标注

          本文链接:https://www.haomeiwen.com/subject/wiqzbktx.html