码迷,mamicode.com
首页 > 其他好文 > 详细

baidu地图:实现多点连线渲染

时间:2017-07-13 23:48:18      阅读:438      评论:0      收藏:0      [点我收藏+]

标签:font   view   body   com   javascrip   缩放   utf-8   head   points   

<script type="text/javascript">
var points = [
{"Lng":120.17787645967861,"Lat":30.251826748722667},
{"Lng":120.17786646842835,"Lat":30.251826580357911}
];    
</script>
<!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=E06eb9d756d0eafc722effb355657b4c"></script>
    <title>GPS转百度</title>
</head>
<body>
    <div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
    // 百度地图API功能
    //GPS坐标
    var x = 120.17730456267518;
    var y = 30.250142055599344;
    var ggPoint = new BMap.Point(x,y);
    //地图初始化
    var bm = new BMap.Map("allmap");
    bm.centerAndZoom(ggPoint, 25);
    //bm.addControl(new BMap.NavigationControl());
    bm.addControl(new BMap.MapTypeControl());   //添加地图类型控件  
    bm.setCurrentCity("杭州");          // 设置地图显示的城市 此项是必须设置的  
    bm.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放  

    
    var pointsGps=[];
    for(var i=0;i<points.length;i++){
        pointsGps.push(new BMap.Point(points[i].Lng, points[i].Lat));
    }
    
    
    var polyline = new BMap.Polyline(pointsGps, {strokeColor:"red", strokeWeight:2, strokeOpacity:0.5});   //创建折线
    bm.addOverlay(polyline);   //增加折线
    
    for(var i=0;i<pointsGps.length;i++){
        //添加gps marker和label
        var markergg = new BMap.Marker(pointsGps[i]);
        bm.addOverlay(markergg); //添加GPS marker
        var labelgg = new BMap.Label(i+1,{offset:new BMap.Size(20,-10)});
        markergg.setLabel(labelgg); //添加GPS label
    }
</script>

 

baidu地图:实现多点连线渲染

标签:font   view   body   com   javascrip   缩放   utf-8   head   points   

原文地址:http://www.cnblogs.com/yy3b2007com/p/7163588.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!