美文网首页
uni-app 获取位置并转为省市区

uni-app 获取位置并转为省市区

作者: 安徒生1997 | 来源:发表于2022-03-24 23:06 被阅读0次

getAddress() {

let _this = this

uni.getLocation({

type: 'wgs84',

geocode: true,

success: function (res) {

// console.log('当前位置:' + JSON.stringify(res));

var point = new plus.maps.Point(res.longitude, res.latitude);

plus.maps.Map.reverseGeocode(point,{},function(event) {

var reg = /.+?(省|市|自治区|自治州|县|区)/g;

// console.log(event.address.match(reg));

let newCity = event.address.match(reg)

_this.citys = newCity[0] + '-' + newCity[1]

})

},

fail: function (fail) {

// console.log('当前位置:' + JSON.stringify(fail));

_this.citys = '北京市-市辖区'

},

});

}

相关文章

网友评论

      本文标题:uni-app 获取位置并转为省市区

      本文链接:https://www.haomeiwen.com/subject/qyfrjrtx.html