How to set marker? dynamically by Mini Program

how does Mini Program set marker? dynamically
if you encounter a problem when using the map component, first add the code
Page ({
data: {

)
getbranchListRequest: {
  center: "",
  city: "3",
  gearBox: "AUTO",
  priceEnd: "500",
  priceStart: "0",
  rentType: "0",
  vehType: "ECON"
},
map: {
  markers: [],
  longitude: 0,
  latitude: 0,
  scale: 17,
  hasMarkers:false
}  

},

bindcontroltap: function (e) {

switch (e.controlId) {
  //
  case 1:
    wx.navigateTo({
      url: "../personal/personal",
    })
    break;
  //
  case 2:
    wx.createMapContext("map", this).moveToLocation();
    this.setData({
      "map.scale": 12
    })
    break;
}

},

findCar: function () {

wx.navigateTo({
  url: "../usecar/usecar",
})

},
/ *

  • Lifecycle function-- load the listening page

* /
onLoad: function (options) {

this.timer = options.timer;
var that = this;
wx.getLocation({
  type: "gcj02", // 
  success: (res) => {
    that.setData({
      "map.longitude": res.longitude,
      "map.latitude": res.latitude,
      "getbranchListRequest.center": res.longitude + "," + res.latitude
    })
    this.initmarker();
    
  },   

},
initmarker: function () {

let that = this;
let url = app.globalData.api.GET_BRANCH_LIST
let getbranchListRequest = JSON.stringify(that.data.getbranchListRequest)
http.http(url, getbranchListRequest,
  function success(res) {
    console.log(res);
    let a = []
    a = res.data.data
    let i
    for(i=0;i<=res.data.data.length;iPP){      
      that.setData({
        "map.markers": [{
          id: a[i].branchId,
          latitude: a[i].lat,
          longitude: a[i].lng,
          iconPath: "/images/ic_point.png",
          width: 40,
          height: 50
        }],
        "map.hasMarkers": true
      })
    }
    console.log(that.data.map.markers)

  }, function fail(res) {
    console.log(res);

  })

},
})

there are two problems. The first is how to get the data in the array from the background and put it into marker. Some of the data returned by the background is useless.

clipboard.png
mapwx:ifflasemarkertruemap

clipboard.png
clipboard.png
clipboard.png

Mar.08,2021

I have the same problem. Have you solved it?

Menu