mapCtx.getCenterLocation始终返回0值的经纬度
发布于 4 年前 作者 xiulan72 1811 次浏览 来自 问答
Page({
  onReady: function (e) {    // 使用 wx.createMapContext 获取 map 上下文
    this.mapCtx = wx.createMapContext('myMap')
  },

 getCenterLocation: function () {    

    this.mapCtx.getCenterLocation({

        success: function(res){        

            console.log(res.longitude)        

            console.log(res.latitude)

          }

   })

 },

})

//我的代码

onLoad: function (options) {

    var that = this;

    that.mapCtx = wx.createMapContext(‘myMap’);

// 获取当前位置并移动到此位置

    wx.getLocation({

        success: function (res) {

        var longitude = res.longitude;

        var latitude = res.latitude;

        // console.log(res)

        that.setData({

            longitude: longitude,

            latitude: latitude

        })

        setTimeout(function () {

            that.mapCtx.moveToLocation();

        }, 300);

        }

    });

},

onShow: function () {

    var that = this;

// 获取中心位置

    console.log(that.mapCtx);

    that.mapCtx.getCenterLocation({

    success: function (res) {

        console.log(res);

        var centerLgt = res.longitude;

        var centerLat = res.latitude;    

        if (centerLgt == that.data.centerLgt && centerLat == that.data.centerLat) {

            return;

        } else {

        that.setData({

            centerLgt: centerLgt,

            centerLat: centerLat

});

        getMarkers.call(that, centerLat, centerLgt);

            }

        }

    });

},

//console返回的结果

  1. callbackId:"callback110_0_4"

  2. errMsg:"getMapCenterLocation:ok"

  3. latitude:0

  4. longitude:0

  5. mapId:0

  6. method:"getMapCenterLocation"

是什么原因造成的呢?

3 回复

@emmm 已经解决了

遇到同样问题,怎么解决的

请问你解决了吗?

回到顶部