Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1.  
  2. $(document).ready(function(){
  3. $output = "";
  4. $lat = "";
  5. $long = "";
  6. $apiURl = "";
  7. $toStringWeather = "";
  8. $temp = "";
  9. $counter = 2;
  10.  
  11. $.getJSON('http://ip-api.com/json', function(data) {
  12. console.log(data);
  13. lat = data.lat;
  14. long = data.lon;
  15. apiURl = "http://api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+long+"&units=metric&APPID=9831e8cfbb31cc22a052364d2d9dc1c8";
  16.  
  17. $.getJSON(apiURl,function(json) {
  18. $(".weather").html(JSON.stringify(json));
  19. $location = " You are located in: <strong>Country:</strong> " + json.sys["country"] + " <strong>City:</strong> " + json.name;
  20. console.log($location);
  21. $weather = " The weather in your area is currently: " +json.weather[0].main;
  22. $temp += "The temperature in your area is currently: " + json.main["temp"];
  23. $joined = $location + "<br>" + $weather + "<br>";
  24. $(".weather").html("<p>" + $joined + "</p>");
  25. $(".temp").html("The temperature in your area is currently: " + $temp + " C degrees");
  26. });
  27. });
  28.  
  29. $(document).on('click', '.switch', function() {
  30. var x = parseInt($temp);
  31. x = x * 1.8+32;
  32. if ($counter % 2 == 0) {
  33. $(".temp").html("The temperature in your area is currently: " + x + " F degrees");
  34. $counter++;}
  35. else {
  36. $(".temp").html("The temperature in your area is currently: " + $temp + " C degrees");
  37. $counter++;
  38. }
  39. });
  40. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement