微信小程序调用腾讯地图,点击选择并返回选择位置数据!
发布于 4 年前 作者 weimao 3832 次浏览 来自 分享

选择前

选择位置

选择后

上代码:

//wxml
<view class="cu-form-group border-bottom">
      <view class="title">详细地址</view>
      <input class="address-right" disabled='{{true}}' required="{{true}}" name="address" value="{{address}}"
        bindtap="AddressInput" />
      <text class="cuIcon-locationfill text-green"></text>
    </view> 
js
AddressInput(e) {
        wx.getSetting({
            successfunction (res{
                var statu = res.authSetting;
                if (!statu['scope.userLocation']) {
                    wx.showModal({
                        title'发布需要授权定位功能',
                        content'请确认授权,否则地图功能将无法使用',
                        successfunction (tip{
                            if (tip.confirm) {
                                console.log(tip.confirm)
                                wx.openSetting({
                                    successfunction (data{
                                        if (data.authSetting["scope.userLocation"] === true) {
                                            app.ShowToast("授权成功")
                                        } else {
                                            app.ShowToast("授权失败,请重新点击")
                                        }
                                    },
                                    failfunction (data{
                                        console.log(data)

                                    }
                                })
                            } else {
                                app.ShowToast("授权失败,请重新点击")
                            }
                        },
                    })
                }
            }
        });
        var that = this;
        wx.chooseLocation({
            successfunction (res{
                console.log(res)
                that.setData({
                    address: res.address,      //调用成功直接设置地址
                    resident: res.name,
                    longitude: res.longitude,
                    latitude: res.latitude
                })
            }
        })
    },
回到顶部