微信小程序地图开发电子围栏与后端联调

时间:2025-04-02 16:33:26
//进行骑行区域查找,根据经纬度查询附近的骑行区域 function finddrivingArea(that, log, lat) { //请求后端数据 wx.request({ url: "http://localhost:8084/get/drivingAreas", method: 'GET', data: { longitude: log, latitude: lat, }, success: function (res) { console.log(res) //(res) //函数式编程,将每个GeoResult中的单词数据迭代出来 var object1={"points":null, strokeWidth:2, strokeColor:"#FF000010",fillColor:"#FF000020"}; const spolygons = res.data.content.map((reslut) => { var polygon1 =JSON.stringify(reslut.content.geoJsonPolygon) var polygon2=reslut.content.geoJsonPolygon; var points=[] console.log('polygon1 '+polygon1) console.log(' '+JSON.stringify(polygon2.points)) console.log(' '+polygon2.points.length) polygon2.points.forEach(element=>{ var temp={} temp['longitude']=element.x; temp['latitude']=element.y; points.push(temp); }); console.log(points) return {//返回 polygons所需要的数据格式 points:points, strokeWidth:2, strokeColor:"#FF000010", fillColor:"#FF000020" }; }); // 修改data里面的polygons that.setData({ lat: lat, log: log, polygons:spolygons }); } }) }