You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
import amap from './amap-wx.130.js';
|
|
/**
|
|
* 获取天气
|
|
* @param {*}
|
|
*/
|
|
function getLocationAndWeather(amapMiniKey,amapWebKey) {
|
|
return new Promise((resolve, reject) => {
|
|
let amapPlugin, city, adcode, temperature, weather;
|
|
amapPlugin = new amap.AMapWX({
|
|
key: amapMiniKey || 'e2ee6a41e07306db2214f0edfa86f73a'
|
|
});
|
|
amapPlugin.getRegeo({
|
|
success: (res) => {
|
|
console.log(res,'坐标信息')
|
|
city = res[0].regeocodeData.addressComponent.city
|
|
adcode = res[0].regeocodeData.addressComponent.adcode
|
|
uni.request({
|
|
url: 'https://restapi.amap.com/v3/weather/weatherInfo', //高德地图查询天气
|
|
method: 'GET',
|
|
data: {
|
|
key: amapWebKey || '7d0d358762ba1af430645a7592f75789',
|
|
city: adcode,
|
|
},
|
|
success: (e) => {
|
|
temperature = e.data.lives[0].temperature
|
|
weather = e.data.lives[0].weather
|
|
resolve({
|
|
city,
|
|
temperature,
|
|
weather
|
|
})
|
|
},
|
|
fail(e) {
|
|
}
|
|
});
|
|
},
|
|
fail: function(info) {
|
|
reject(info)
|
|
}
|
|
});
|
|
})
|
|
}
|
|
|
|
module.exports = {
|
|
getLocationAndWeather
|
|
}
|
|
|