Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function(){
- $output = "";
- $lat = "";
- $long = "";
- $apiURl = "";
- $toStringWeather = "";
- $temp = "";
- $counter = 2;
- $.getJSON('http://ip-api.com/json', function(data) {
- console.log(data);
- lat = data.lat;
- long = data.lon;
- apiURl = "http://api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+long+"&units=metric&APPID=9831e8cfbb31cc22a052364d2d9dc1c8";
- $.getJSON(apiURl,function(json) {
- $(".weather").html(JSON.stringify(json));
- $location = " You are located in: <strong>Country:</strong> " + json.sys["country"] + " <strong>City:</strong> " + json.name;
- console.log($location);
- $weather = " The weather in your area is currently: " +json.weather[0].main;
- $temp += "The temperature in your area is currently: " + json.main["temp"];
- $joined = $location + "<br>" + $weather + "<br>";
- $(".weather").html("<p>" + $joined + "</p>");
- $(".temp").html("The temperature in your area is currently: " + $temp + " C degrees");
- });
- });
- $(document).on('click', '.switch', function() {
- var x = parseInt($temp);
- x = x * 1.8+32;
- if ($counter % 2 == 0) {
- $(".temp").html("The temperature in your area is currently: " + x + " F degrees");
- $counter++;}
- else {
- $(".temp").html("The temperature in your area is currently: " + $temp + " C degrees");
- $counter++;
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement