Before anyone says that my reasoning for posting this question is unclear I would like to say that I myself have no idea whats wrong with this code And why it does not work
I have tried everything possible I could but I could'nt find the what the error is . So I am unable to pinpoint what the error is .
My only request to the experts on stackoverflow is to check if this code works for you and check where I have gone wrong .
I do not want you to tell me the answer . Just show me the error so I can fix it myself .
Please do not block this question. I really do need help.
var api = "http://ift.tt/2vkF9yP?";
var temp ;
var curtemp = cel;
var cel;
var fahTemp;
$( document ).ready(function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var lat = "lat=" + position.coords.latitude;
var lon = "lon=" + position.coords.longitude;
getWeather(lat, lon);
});
} else {
console.log("Geolocation is not supported by this browser.");
}
$("#c/f").click(function(){
temp = $("#c/f").text();
var newTempUnit = temp == cel ? fahTemp : cel;
$("#c/f").text(newTempUnit);
if (newTempUnit == fahTemp) {
fahTemp = Math.round(parseInt($("#temp").html()) * 9 / 5 + 32);
$("#temp").text(fahTemp + " " + String.fromCharCode(176));}
else {
$("#temp").text(cel + " " + String.fromCharCode(176));
}
});
});
function getWeather(lat,lon){
var urlString = api + lat + "&" + lon;
$.ajax({ url: urlString, success: function (result) {
$("#city").text(result.name + ", ");
$("#country").text(result.sys.country);
cel = Math.round(result.main.temp * 10) / 10;
$("#temp").text(cel + " " + String.fromCharCode(176)); $("#temp").text(curtemp);
}
});
}
Aucun commentaire:
Enregistrer un commentaire