小程序 (地址选择1)--选取、搜索地点并显示

效果:(直接复制代码,可查看效果)
可以通过拖动地图,搜索地址,选择地址,并将地址值传给文本框
在这里插入图片描述
进入以下界面
在这里插入图片描述
点击确定后。
在这里插入图片描述
代码如下:

wxml:

 <view class="box2">
    <view class="box2_left">收货地址</view>
    <input type="text" class="box2_right" placeholder="请选择收货地址" bindtap="onChangeAddress" value='{{chooseAddress}}'></input>
    <view class="fuhao"  bindtap="onChangeAddress">></view>
  </view>

wxss:

.box2{
  width: 680rpx;
  min-height: 90rpx;
  display: flex;
  flex-direction: row;
  align-items: center;
  border-bottom: solid 2rpx #D7D7D7;
}
.box2_left{
  width: 180rpx;
  font-size: 15px;
  color: #000000;
}
.box2_right{
  width: 406rpx;
  min-height: 90rpx;
  display: flex;
  align-items: center;
  font-size: 14px;
}
.fuhao{
  width: 70rpx;
  height:90rpx;
  font-size: 25px;
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
}

js:

  //移动选点
  onChangeAddress: function () {
    var _page = this;
    wx.chooseLocation({
      success: function (res) {
        _page.setData({
          chooseAddress: res.name
        });
      },
      fail: function (err) {
        console.log(err)
      }
    });
  },

这里显示在文本框的内容只是返回结果中的name,整个返回结果是下面这中形式的:
在这里插入图片描述
wx.chooseLocation:在文档中的位置点这里

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值