1. 程式人生 > >ionic4使用高德地圖踩坑

ionic4使用高德地圖踩坑

//初始化地圖物件,載入地圖 var map = new AMap.Map("container", { resizeEnable: true, zoom: 13 }); var pos = [116.377904, 39.915423] var marker = new AMap.Marker({ map: map, position: pos }); var path = [ [116.368904, 39.913423], [116.382122
, 39.901176], [116.387271, 39.912501], [116.398258, 39.904600] ] var closestPositionOnLine = AMap.GeometryUtil.closestOnLine(pos,path) var polyline = new AMap.Polyline({ map: map, path: path, strokeColor:'red', }); var polyline2 = new AMap.Polyline({ map: map, strokeStyle:'dashed'
, strokeColor:'blue', strokeWeight:1, path: [pos,closestPositionOnLine] }); new AMap.Text({ text:'點線距離'+Math.round(AMap.GeometryUtil.distanceToLine(pos,path))+'米', position:[(pos[0]+closestPositionOnLine[0])/2,(pos[1]+closestPositionOnLine[1])/2], map:map, style:{'background-color'
:'#ccccff', 'border-color':'green', 'font-size':'12px'} }) map.setFitView();