Skip to content

Instantly share code, notes, and snippets.

@azlan
Created August 6, 2016 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azlan/8d2b44795227e47fdde17c308c1fdf4a to your computer and use it in GitHub Desktop.
Save azlan/8d2b44795227e47fdde17c308c1fdf4a to your computer and use it in GitHub Desktop.
weather
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>z</title>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<button onclick='getWeather()'>Get weather</button>
<p id='location'></p>
<p id='weather'></p>
<p id='pict'></p>
<p id='loc'></p>
<script>
function getWeather() {
var xt, obj, place = "http://api.openweathermap.org/data/2.5/weather?q=";
$.getJSON('http://ipinfo.io', function(data) {
xt = JSON.stringify(data);
xt = JSON.parse(xt);
//place += 'Los Angeles';
place += xt.city;
place += "&APPID=1c4f36b03d4768daaf2eec6dc678a06b";
console.log(place);
//data.clear();
$.getJSON(place, function(data) {
obj = JSON.stringify(data);
obj = JSON.parse(obj);
console.log(obj);
$('#location').html(obj.name + ', ' + obj.sys.country);
$('#weather').html(obj.main.temp + " Farenheit");
$('#pict').html(obj.weather[0].description);
//$('#loc').html(xt.loc);
});
});
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment