天天看點

微信小程式----Uncaught ReferenceError: ret is not defined

圖檔

微信小程式----Uncaught ReferenceError: ret is not defined

出現錯誤場景

微信小程式輸入位址進行定位,在傳回的資料進行處理時報錯。

報錯原因

在擷取location取值時将經緯度取反,location的格式是**‘經度,緯度’**,在取值的時候’緯度,經度’,導緻報錯。

報錯代碼:

myAmap.getInputtips({
      keywords: '歐尚庭院',
      city: '成都',
      success(res) {
        var tip = res.tips[0];
        //錯誤地方
        *var la = tip.location.split(',')[0];*
        *var lo = tip.location.split(',')[1];*

        _this.setData({
          latitude: la,
          longitude: lo,
          location: tip.location,
          markers: [{
            id: 0,
            latitude: la,
            longitude: lo,
            iconPath: '../../src/images/ding.png',
            width: 32,
            height: 32
          }]
        })
      }
    })           

複制

修改後的正确代碼:

myAmap.getInputtips({
      keywords: '歐尚庭院',
      city: '成都',
      success(res) {
        var tip = res.tips[0];
        //location的格式**'經度,緯度'**
        var lo = tip.location.split(',')[0];
        var la = tip.location.split(',')[1];

        _this.setData({
          latitude: la,
          longitude: lo,
          location: tip.location,
          markers: [{
            id: 0,
            latitude: la,
            longitude: lo,
            iconPath: '../../src/images/ding.png',
            width: 32,
            height: 32
          }]
        })
      }
    })           

複制

注意

  1. 認真閱讀文檔,按照文檔給的标準進行資料處理;
  2. 按照文檔格式解析資料,減少錯誤。