使用微信小程序wx.chooseLocation获取定位

首先看一下结果:

我们的需求是新增地址后实现定位,并回显,当时考虑调用腾讯或百度地图的api,但是发现利用微信选择位置API,获得经纬度信息,然后讲拿到的值回显到页面就ok了,更简单便捷,内容如下:

 

 

<view class="center-input-box">
      <view class="center-input-text">收货地址:</view>
      <view class="center-input-input" bindtap="toPosition">
        <text class="iconfont icon-weizhi wz"></text>
        <input name="houseAddress" id="houseAddress" value="{{houseAddress}}" placeholder="点击选择收货地址" placeholder-style="color:#a4a4a4;" type="text" maxlength="100" disabled></input>
      </view>
</view>
toPosition:function(e){
  var that = this;
  wx.chooseLocation({
    success: function (lb) {},
    complete: function (lb) {
      that.setData({
        houseAddress:lb.name
      })
    },
    cancel: function (lb) {
    },
    fail: function (lb) {
      console.log(lb)
    }
  })
},
.center-input-box {
  display: flex;
  align-items: center;
  padding: 20rpx;
  border-bottom: 1px solid #efefef;
}
.center-input-text{
  margin-right: 2%;
}
.center-input-input{
  width: 70%;
  height: auto;
  margin-left: 4%;
  position: relative;
}
.center-input-input input{
  width: 100%;
  height: 55rpx;
  line-height: 55rpx;
  padding-top: 12rpx;
  display: inline-block;
}
.wz{
  position: absolute;
  top:29%;
  left: -8%;
}

简单粗暴的完成了定位,适合偷懒的小伙伴

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值