首页 > 编程语言 >微信小程序 wx.chooseLocation定位获取地址,并解析省市区

微信小程序 wx.chooseLocation定位获取地址,并解析省市区

时间:2023-01-18 16:57:21浏览次数:72  
标签:chooseLocation 微信 cityName let res myLocation wx

 

 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

相关文章