微信小程序获取位置后切割省市区

getaddress(){
 let that = this
  wx.chooseLocation({
      success: res=>{
         console.log(res)
      let address = res.address;
      let regex = "(?[^省]+省|.+自治区)(?[^自治州]+自治州|[^市]+市|[^盟]+盟|[^地区]+地区|.+区划)(?[^市]+市|[^县]+县|[^旗]+旗|.+区)?(?[^区]+区|.+镇)?(?.*)";
      const provinces = address.match(regex)[1];
      const citys = address.match(regex)[2];
      const districts = address.match(regex)[3];
      const addressss = address.match(regex)[5]
      this.setData({
        show:true,
        latitude:res.latitude,
        longitude:res.longitude,
        city:provinces+','+citys+','+districts,
        address:addressss,
        markers: [{
          iconPath: "/images/dingwei.png",
          id: 0,
          latitude: res.latitude,
          longitude: res.longitude,
          width: 50,
          height: 50
        }],
       })
      }
    })  
},

你可能感兴趣的:(微信小程序,小程序)