Conf(地图):使用天地图定位获取省市区

This commit is contained in:
lifizer
2026-01-05 11:03:48 +08:00
parent f4fcc7e8f5
commit 1780c4ff0a
12 changed files with 115 additions and 364 deletions
+7 -68
View File
@@ -40,8 +40,7 @@
<script>
import {
fetchSpecialty
} from "@/api/shop";
import config from '@/utils/mapConfig';
} from "@/api/shop"
export default {
data() {
@@ -53,12 +52,12 @@ export default {
}
},
onShow() {
let memCityName = uni.getStorageSync("cityName")
const memCityName = uni.getStorageSync("cityName")
if (memCityName.length) {
this.cityName = memCityName;
this.page = 1;
this.list = [];
this.fetchList(this.cityName);
this.cityName = memCityName
this.page = 1
this.list = []
this.fetchList(this.cityName)
uni.removeStorageSync("cityName")
}
},
@@ -89,67 +88,7 @@ export default {
})
}
})
},
//获取当前定位地址
getCurAddress() {
var that = this;
//定位
uni.showLoading({
title: '定位中...'
});
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, {
output: 'jsonp',
}).then(json => {
// Success.
uni.hideLoading();
that.cityName = json.result.ad_info.city;
//定位成功刷新数据
that.fetchList()
}).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) {
uni.hideLoading();
that.cityName = res.data.result.ad_info.city;
//定位成功刷新数据
that.fetchList()
},
fail: function (res) {
console.log('地址解析失败');
uni.hideLoading();
},
complete: function () {
}
});
// #endif
},
fail: function (res) {
uni.hideLoading();
}
});
},
}
}
}
</script>