voila je rencontre un problème pour mettre en place mes icon du site https://erikflowers.github.io/weather-icons/ avec api
voila api marche très bien je reçois la température
mon code :
Code : Tout sélectionner
$(document).ready(()=>{
function temperature() {
function getLocation() {
const position = {
coords:{
latitude: 48.8534,
longitude: 2.3488
}
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(getAPI,function showError(error) {
getAPI(position)
} );
} else {
getAPI(position)
}
};
getLocation();
function getAPI(position){
const lat = position.coords.latitude,lon = position.coords.longitude;
const lien = `http://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&units=metric&ppid=xxxxxxxxxxxxxxxxxxxxxxxxxxxx`
window.fetch(lien)
.then(res => res.json())
.then(resJson => {
$('#temperature').text(Math.round(resJson.main.temp))
$weatherEl = $("#temperature");
console.log($weatherEl)
var icon = resJson.weather[0].icon;
console.log (icon);
var now = new Date();
console.log (now);
var shuruq = prayer.getCurrentDateForPrayerTime(prayer.getChouroukTime());
console.log (shuruq);
var maghrib = prayer.getCurrentDateForPrayerTime(prayer.getTimeByIndex(3));
console.log (maghrib);
if (now.getTime() > shuruq.getTime() && now.getTime() < maghrib.getTime()) {
icon = "day-" + icon;
} else {
// fix night sunny
if (icon = 'sunny') {
icon = 'clear';
}
icon = "night-" + icon;
}
$weatherEl.attr("i").attr('class', 'wi wi-' + icon);
})
}
}
temperature();
})
Code : Tout sélectionner
<div class="temperature">
<i class="wi wi-"></i>
<div id="temperature"></div>
<sup>°C</sup>
</div>