通过高德地图api自己装了点我用的方法,大家可以看下

  

 1 var pz_map = {
 2     //地图加载
 3     load : function(){
 4         map = new BMap.Map("map");          // 创建地图实例
 5         var point = new BMap.Point(116.43, 23.43);  // 创建点坐标  
 6         map.centerAndZoom('太原',6);        // 初始化地图,设置中心点坐标和地图级别
 7         map.enableScrollWheelZoom(true);    //开启滚轮缩放地图
 8         //开始
 9         this.addMarker(112.33,37.54,'fh.png');
10         //结束
11         this.addMarker(116.2317,39.5427,'sh.png');
12         //状态
13         this.addMarker(116.2317,39.5427,'yqs.png');
14 
15         //添加线
16         this.addPolyline();
17     },
18     //添加marker点
19     addMarker : function(lnt,lat,address){
20         var pt = new BMap.Point(lnt, lat);
21         var size = new BMap.Size(22,22);
22         if(address == 'yqs.png'){
23             size = new BMap.Size(-1,60);
24         }
25         var myIcon = new BMap.Icon("images/map/"+address, size);
26         var marker = new BMap.Marker(pt,{icon:myIcon});  // 创建标注
27         map.addOverlay(marker);    // 将标注添加到地图中
28     },
29     //当前位置添加聚合点
30     gpsMarker : function(){
31         function myFun(result){
32             console.log(result);
33             var cityName = result.name;
34             alert("当前定位城市:"+cityName);
35         }
36         var myCity = new BMap.LocalCity();
37         myCity.get(myFun);
38     },
39     //添加折线
40     addPolyline : function(){
41         //线条经纬度设置
42         var lines = [
43             new BMap.Point(116.2317,39.5427),
44             new BMap.Point(112.33,37.54)
45         ];
46         //线条颜色设置
47         var PolylineOptions = {
48             strokeColor : '#50BCA6',    //颜色
49             strokeWeight : 2,    //宽度
50             strokeOpacity : 1    //透明度
51         };
52 
53         var line = new BMap.Polyline(lines,PolylineOptions);
54         map.addOverlay(line);
55         
56     }
57 }

 

posted on 2019-05-06 14:31  Cc_Pz  阅读(243)  评论(0编辑  收藏  举报