收藏
回答

mapCtx.getCenterLocation获取中心定位点为什么和data设置定位不一致?

问题:页面地图设置的中心点定位,有概率未根据后台data中放置的经纬度自动渲染,只能再次手动代码调整中心点定位,这会导致用户体验不太好。

问题大概率出现企业微信进入小程序,在2个都拥有地图页面的切换后,后台AJAX调用地址,赋值到DATA中未自动渲染。

   this.mapCtx.getCenterLocation 获取的中心定位点和从data中获取设置的定位点不一致

  this.mapCtx.getCenterLocation({

      success: function (e) {

        if(e.longitude!=cpage.data.longitude){

        //将地图中心移动到当前定位点,需要配合map组件的show-location使用

        cpage.mapCtx.moveToLocation({

          longitude:cpage.data.longitude,

          latitude:cpage.data.latitude

        });

        }

        console.log(cpage.data.longitude)

        console.log(cpage.data.latitude)

        console.log("1经度" + e.longitude)

        console.log("2纬度" + e.latitude)

      },

      fail: function (res) {

        console.log(res)

        },

      complete: function (res) {

        console.log(res)

        },

    });

  },

页面地图代码:

 <map 

    id="m_map_new"

    bindtap="goBigMap"

    style="width: 100%; height: 590rpx;"

    longitude="{{longitude}}"

    latitude="{{latitude}}"

    markers="{{markers}}"

    show-location="{{true}}"

    scale="12"

    bindcallouttap="clickMarker"

    min-scale="8"

    max-scale="19"

>

</map>


最后一次编辑于  2021-09-23
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容