小程序 (地址选择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:在文档中的位置点这里

发布了45 篇原创文章 · 获赞 6 · 访问量 1176

猜你喜欢

转载自blog.csdn.net/qq_41219586/article/details/103553622