首页 > 其他 > 详细

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

时间:2017-07-13 23:24:21      阅读:278      评论:0      收藏:0      [点我收藏+]
<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地图:实现多点连线渲染

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!