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

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 = '北京市-市辖区'

},

});

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容