收藏
回答

mapCtx.getCenterLocation始终返回0值的经纬度

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 个回答

  • 凉柚i °
    凉柚i °
    2018-06-07

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

    2018-06-07
    有用
    回复
  • James Lam
    James Lam
    2018-05-09

    @emmm 已经解决了

    2018-05-09
    有用
    回复 2
    • W
      W
      2018-07-24

      怎么解决的?

      2018-07-24
      回复
    • James Lam
      James Lam
      2018-07-26回复W

      我忘了,太久远的事(哭笑脸)

      2018-07-26
      回复
  • emmm
    emmm
    2018-04-16

    请问你解决了吗?

    2018-04-16
    有用
    回复
登录 后发表内容