onLoad(option) {
this.getAddress()
}
getAddress() {
let self = this;
uni.getLocation({
type: 'gcj02',
geocode: true,
success: function(res) {
var point = new plus.maps.Point(res.longitude, res.latitude);
plus.maps.Map.reverseGeocode(point, {}, (event) => {
var address = event.address; // 转换后的地理位置
var point = event.coord; // 转换后的坐标信息
var coordType = event.coordType; // 转换后的坐标系类型
var reg = /.+?(省|市|自治区|自治州|县|区)/g;
var addressList = address.match(reg).toString().split(",");
//注意 因为存在直辖市, 当所在地区为普通省市时,addressList.length == 3,city = addressList[1];当所在地区为直辖市时addressList.length == 2,city = addressList[0];
// let city = addressList.length == 3 ? addressList[1] : addressList[0];
if (addressList.length == 2) {
self.citys = addressList[0] + addressList[1];
self.cityFlag = addressList[0];
} else if (addressList.length == 3) {
self.citys = addressList[1] + addressList[2];
self.cityFlag = addressList[1];
} else if (addressList.length == 4) {
self.citys = addressList[1] + addressList[2];
self.cityFlag = addressList[1];
} else {
self.citys = addressList[1] + addressList[2];
self.cityFlag = addressList[1];
}
self.getDeviceChild();
},
function(e) {
console.log("失败回调", e);
}
);
},
fail: function(err) {
uni.showToast({
title: '获取定位失败',
icon: 'error'
});
}
});
},
0 个回复