A Pen by Ashok Borra on CodePen.
Created
November 27, 2015 15:28
-
-
Save coded9/c07134fc898dd8769d55 to your computer and use it in GitHub Desktop.
Local Weather App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1 id="yourcity"></h1> | |
<h4 id="currWeather"></h4> | |
<h1>Want to check the weather?</h1> | |
Enter the city name:<input type="text" name="cityname" id ="cityname"/> | |
<button class="sub">Submit</button><br> | |
<h4 id="weatherr"></h4> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
var yourLoc; | |
getLocation(); | |
function getLocation(){ | |
$.get("http://ipinfo.io", function(response) { | |
yourLocation = response.city+','+response.region ; | |
$.ajax({ | |
type:"GET", | |
url: "http://api.openweathermap.org/data/2.5/weather?q="+yourLocation+"&appid=2de143494c0b295cca9337e1e96b00e0&units=metric", | |
dataType: 'jsonp', | |
success: function(results){ | |
console.log('success',results); | |
currWeath = results.name +'-'+results.sys.country+'<br><br>'+'Temperature in Celsius: '+results.main.temp+'°C'+'<br><br>'+results.weather[0].description; | |
$("#currWeather").html(currWeath); | |
} | |
}); | |
$("#yourcity").text("Hello visitor from "+yourLocation); | |
}, "jsonp"); | |
} | |
$(".sub").click(function(){ | |
/*$.getJSON("http://api.openweathermap.org/data/2.5/weather?q=hyderabad&appid=2de143494c0b295cca9337e1e96b00e0", function(json) { | |
console.log(json); | |
});*/ | |
var loc = $("#cityname").val(); | |
$("#weatherr").text("Loadinggg..."); | |
$.ajax({ | |
type:"GET", | |
url: "http://api.openweathermap.org/data/2.5/weather?q="+loc+"&appid=2de143494c0b295cca9337e1e96b00e0&units=metric", | |
dataType: 'jsonp', | |
success: function(results){ | |
console.log('success',results); | |
weather = results.name +'-'+results.sys.country+'<br><br>'+'Temperature in Celsius: '+results.main.temp+'°C'+'<br><br>'+results.weather[0].description; | |
$("#weatherr").html(weather); | |
} | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="http://www.geoplugin.net/javascript.gp"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment