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
标签:chooseLocation,微信,cityName,let,res,myLocation,wx From: https://www.cnblogs.com/jiduoduo/p/17060193.html