微信小程序map组件拖拽地图获取经纬度,地址,带定位点范围(中心点固定)

微信小程序map组件之移动map选取位置,效果图如下:
在这里插入图片描述
微信小程序map组件,实现拖拽定位,获取定位位置,点击cover-image回到定位原点
手机效果相同。
废话不多说,上代码

wxml代码:

    <view class="container">
      <map id="map4select" longitude="{{longitude}}" latitude="{{latitude}}" scale="14" controls="{{controls}}" markers="{{markers}}" show-location bindcontroltap="controltap" polyline="{{polyline}}" bindmarkertap="markertap" circles="{{circles}}" bindregionchange="regionchange" >
        <cover-image class="cover-image" bindtap="my_location" src="/imgs/my_location.png" />
        <cover-image class="cover-image_confirm" bindtap="confirm_bag" src="/imgs/confirm.png" />
      </map>
    </view>
  regionchange(e) {
    console.log(e)
    // 地图发生变化的时候,获取中间点,也就是用户选择的位置toFixed
    if (e.type == 'end' && (e.causedBy == 'scale' || e.causedBy == 'drag')) {
      console.log(e)
      var that = this;
      this.mapCtx = wx.createMapContext("map4select");
      this.mapCtx.getCenterLocation({
        type: 'gcj02',
        success: function(res) {
          console.log(res)
          that.setData({
            latitude: res.latitude,
            longitude: res.longitude,
            circles: [{
              latitude: res.latitude,
              longitude: res.longitude,
              color: '#FF0000DD',
              fillColor: '#d1edff88',
              radius: 3000,//定位点半径
              strokeWidth: 1
            }]
          })
        }
      })
    }
  },
  //定位到自己的位置事件
  my_location: function(e) {
    var that = this;
    that.onLoad();
  },

可实现拖拽地图获取定位点的经度纬度以及地理位置等操作
详细代码QQ:961052877

  • 5
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值