小程序省市区调用微信原生代码

微信小程序 调用原生微信api 实现省市区地址选择

// page/address/edit.js
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(){
    // 页面关闭
  }
})

 以上是js 代码

 

网页部分(wxml)


    收货地址
    


    详细地址