Conf(地图):使用天地图定位获取省市区
This commit is contained in:
@@ -234,111 +234,6 @@ export default {
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
},
|
||||
//获取当前定位地址
|
||||
getCurAddress() {
|
||||
var that = this;
|
||||
//定位
|
||||
uni.showLoading({
|
||||
title: '定位中...'
|
||||
});
|
||||
//this.getLocation();
|
||||
uni.getLocation({
|
||||
type: 'wgs84',
|
||||
success: function (res) {
|
||||
let latitude = res.latitude;
|
||||
let longitude = res.longitude;
|
||||
|
||||
console.log('latitude:' + latitude + 'longitude:' + longitude)
|
||||
|
||||
// #ifdef H5
|
||||
Vue.jsonp(
|
||||
'https://apis.map.qq.com/ws/geocoder/v1/?location=' + latitude + ',' + longitude + '&key=' + config.key,
|
||||
{
|
||||
//callbackName: 'QQmap',
|
||||
output: 'jsonp',
|
||||
}).then(json => {
|
||||
// Success.
|
||||
uni.hideLoading();
|
||||
|
||||
that.addressText =
|
||||
json.result.ad_info.province + " " + json.result.ad_info.city + " " + json.result.ad_info.district;
|
||||
that.address.province = json.result.ad_info.province;
|
||||
that.address.city = json.result.ad_info.city;
|
||||
that.address.district = json.result.ad_info.district;
|
||||
that.$set(that.userAddress, 'detail', json.result.formatted_addresses.recommend);
|
||||
//that.userAddress.detail = json.result.formatted_addresses.recommend;
|
||||
// that.$refs.cityselect.adjustDefaultValue();
|
||||
|
||||
//设置city_id
|
||||
var pIdx = that.getIndex(that.address.province, that.district);
|
||||
if (pIdx > -1) {
|
||||
var citys = that.district[pIdx].c;
|
||||
var cIdx = that.getIndex(that.address.city, citys);
|
||||
if (cIdx > -1) {
|
||||
var city = citys[cIdx];
|
||||
that.address.city_id = city.v;
|
||||
console.log('city_id:' + city.v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}).catch(err => {
|
||||
// Failed.
|
||||
console.log('地址解析失败:' + JSON.stringify(err));
|
||||
uni.hideLoading();
|
||||
})
|
||||
// #endif
|
||||
|
||||
// #ifndef H5
|
||||
uni.request({
|
||||
url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=' + latitude + ',' + longitude + '&key=' + config.key,
|
||||
success: function (res) {
|
||||
// console.log('res:'+JSON.stringify(res.data));
|
||||
uni.hideLoading();
|
||||
that.addressText =
|
||||
res.data.result.ad_info.province + " " + res.data.result.ad_info.city + " " + res.data.result.ad_info.district;
|
||||
that.address.province = res.data.result.ad_info.province;
|
||||
that.address.city = res.data.result.ad_info.city;
|
||||
that.address.district = res.data.result.ad_info.district;
|
||||
//that.userAddress.detail = res.data.result.formatted_addresses.recommend;
|
||||
that.$set(that.userAddress, 'detail', res.data.result.formatted_addresses.recommend);
|
||||
// that.$refs.cityselect.adjustDefaultValue();
|
||||
//设置city_id
|
||||
var pIdx = that.getIndex(that.address.province, that.district);
|
||||
if (pIdx > -1) {
|
||||
var citys = that.district[pIdx].c;
|
||||
var cIdx = that.getIndex(that.address.city, citys);
|
||||
if (cIdx > -1) {
|
||||
var city = citys[cIdx];
|
||||
that.address.city_id = city.v;
|
||||
console.log('city_id:' + city.v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
fail: function (res) {
|
||||
console.log('地址解析失败');
|
||||
uni.hideLoading();
|
||||
},
|
||||
complete: function () {
|
||||
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
},
|
||||
fail: function (res) {
|
||||
uni.hideLoading();
|
||||
|
||||
// uni.showToast({
|
||||
// title:'城市定位失败:'+JSON.stringify(res),
|
||||
// icon:'none',
|
||||
// duration:2000
|
||||
// })
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
getCityList: function () {
|
||||
let that = this;
|
||||
|
||||
Reference in New Issue
Block a user