小程序API接口chooseLocation获取省市区

//page/API/pages/choose-location/choose-location
Page({  
  data:{},  
  onLoad:function(options){  
    // 页面初始化 options为页面跳转所带来的参数  
  },  
  bingAddressTap:function(){  
    var that = this;  
    wx.chooseLocation({  
      success: function(res){  
        var regex = /^(北京市|天津市|重庆市|上海市|香港特别行政区|澳门特别行政区)/;  
        var REGION_PROVINCE=[];  
        var addressBean = {  
          REGION_PROVINCE:null,  
          REGION_COUNTRY:null,  
          REGION_CITY:null,  
          ADDRESS:null};  
        function regexAddressBean(address, addressBean){  
            regex = /^(.*?[市州]|.*?地区|.*?特别行政区)(.*?[市区县])(.*?)$/g;  
            var addxress = regex.exec(address);  
            addressBean.REGION_CITY=addxress[1];  
            addressBean.REGION_COUNTRY=addxress[2];  
            addressBean.ADDRESS=addxress[3]+"("+res.name+")";  
            console.log(addxress);  
        }  
        if(!(REGION_PROVINCE = regex.exec(res.address))){  
          regex = /^(.*?(省|自治区))(.*?)$/;  
          REGION_PROVINCE = regex.exec(res.address);  
          addressBean.REGION_PROVINCE= REGION_PROVINCE[1];  
          regexAddressBean(REGION_PROVINCE[3],addressBean);  
        } else {  
          addressBean.REGION_PROVINCE= REGION_PROVINCE[1];  
          regexAddressBean(res.address, addressBean);  
        }  
        that.setData({ADDRESS_1_STR:  
        addressBean.REGION_PROVINCE+" "  
        +addressBean.REGION_CITY+""  
        +addressBean.REGION_COUNTRY });  
        that.setData(addressBean);  
      }  
    })  
  },  
  onReady:function(){  
    // 页面渲染完成  
  },  
  onShow:function(){  
    // 页面显示  
  },  
  onHide:function(){  
    // 页面隐藏  
  },  
  onUnload:function(){  
    // 页面关闭  
  }  
})  

你可能感兴趣的:(小程序API接口chooseLocation获取省市区)