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
+11 -48
View File
@@ -74,7 +74,7 @@
</template>
<script>
import config from '@/utils/mapConfig'
import { getCurAddress, getLocation } from "@/utils/common"
import {
getHotelTypeList,
getHotelList
@@ -124,56 +124,19 @@ export default {
})
},
//获取当前定位地址
getCurAddress() {
async getCurAddressFn() {
const that = this
//定位
uni.showLoading({
title: '定位中...'
})
uni.getLocation({
type: 'wgs84',
success: function(res) {
let latitude = res.latitude
let longitude = res.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.paramCity = json.result.ad_info.city
//定位成功刷新数据
that.fetchList()
}).catch(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.paramCity = res.data.result.ad_info.city
//定位成功刷新数据
that.fetchList()
},
fail: function(res) {
uni.hideLoading()
}
})
// #endif
},
fail: function(res) {
uni.hideLoading()
}
})
const map = await getLocation()
if (map.length > 1) {
const {latitude, longitude} = map[1]
getCurAddress(latitude, longitude, address => {
that.cityName = address.city
that.paramCity = address.city
})
}
},
fetchTypeList() {
this.hotelList = []
@@ -195,7 +158,7 @@ export default {
this.fetchList()
uni.removeStorageSync('cityName')
} else {
this.getCurAddress()
this.getCurAddressFn()
}
}
})