微信小程序 wx.chooseLocation定位获取地址,并解析省市区
1、申请开通
操作:小程序后台管理-开发-开发管理-接口设置-- 申请开通
2、调用
wx.chooseLocation(Object object)
wx.chooseLocation({ success: function (res) { var reg = /.+?(省|市|自治区|自治州|县|区)/g; let myLocation = res.address.match(reg); let provinceName = ''; let cityName = ''; let countryName = ''; if (myLocation != undefined && myLocation != null) { provinceName = myLocation[0]; cityName = myLocation[1]; countryName = myLocation[2]; } console.log(provinceName,cityName,countryName); }, fail:function(res){ console.log(res) } })
https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.chooseLocation.html
道法自然