1. 程式人生 > 實用技巧 >高德地圖-折線線路生成,,定位

高德地圖-折線線路生成,,定位

       //獲取標點與生成線路
       getPath:function () {
           var centerposition=[];
           var path=[];
           for(var i=0;i<stationList.length;i++){
             path.push(new AMap.LngLat(stationList[i].y,stationList[i].x));
           }
           AMap.convertFrom(path,'gps',function (status, result) {
               
if(result.info==='ok'){ // vm.drawStationPoint(stationList) $.each(result.locations, function (i, coordinate) { var marker = new AMap.Marker({//建立標記點 position: new AMap.LngLat(coordinate.KL, coordinate.kT), // 經緯度物件,也可以是經緯度構成的一維陣列[116.39, 39.9]
// offset: new AMap.Pixel(10, -20), anchor: 'middle-left' }); pointList.push(marker); TextMap.push(new AMap.Text({//建立標籤 position:new AMap.LngLat(coordinate.KL, coordinate.kT), text: stationList[i].name, offset:
new AMap.Pixel(-60, -20) })); }); // 建立折線例項 var polyline = new AMap.Polyline({ path: result.locations, borderWeight: 2, // 線條寬度,預設為 1 strokeColor: 'red', // 線條顏色 lineJoin: 'round' // 折線拐點連線處樣式 }); routeList.push(polyline); map.add(TextMap); map.add(pointList);//標記點 map.add(routeList); centerposition=[result.locations[0].KL,result.locations[0].kT]; // map.setCenter(centerposition);//定位 map.setFitView();//預設所有都調整到最佳視野 } }); },