Skip to content

Instantly share code, notes, and snippets.

@Luomint
Last active September 27, 2015 02:04
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 Luomint/5d7dbf12271539c2e237 to your computer and use it in GitHub Desktop.
Save Luomint/5d7dbf12271539c2e237 to your computer and use it in GitHub Desktop.
\_(ツ)_/¯
//using html5 method from w3schools
$(document).ready(function() {
var lat = 0;
var long = 0;
var coords = [];
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success);
} else {
window.alert("Geolocation is not supported by this browser.");
}
function success(position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
getWeather(lat,long);
}
$("#button1").css("color","red");
$("#button1").text("color");
$("#button2").css("color","red");
$("#button2").text("color");
weather = [];
wind = [];
clouds = [];
function getWeather(lat,long) {
api1 = "http://api.openweathermap.org/data/2.5/find?lat="+lat+"&lon="+long+"&cnt=1&APPID=be76822350eee7a1b2556597ab290a06";
api2 = "http://api.openweathermap.org/data/2.5/weather?q=London&units=metric&APPID=be76822350eee7a1b2556597ab290a06";
$.getJSON(api2, function(result){
console.log(api1);
$.each(result, function(i, a){
$("#button1").text(result.name);
$("#button2").text(result.main.temp + '' + '°C');
$("#button3").text("Wind is:" + result.wind.speed);
$("#button4").text(result.clouds.all + "% cloudiness");
$("#desc").text(result.weather[0].description);
img = 'http://openweathermap.org/img/w/';
$("#icon").html('<img id="theImg" src=' + img + result.weather[0].icon + '.png>');
$("#iconn").html('<img id="theImg" src="http://openweathermap.org/img/w/01n.png" />');
$("#button5").text(result.main.humidity + "%");
});
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment