Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="Localweatherjs.js"></script>
    <script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>

    <head> 
      <link rel="stylesheet" href="Localweathercss.css">
      <link href="https://fonts.googleapis.com/css?family=Audiowide|Bungee+Shade|Monoton|Nova+Square" rel="stylesheet">

    </head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
  <header class="top-nav">Weather Express</header>
  <body>
    <div class="container-fluid well fixed" style="margin-right:30%; margin-left:30%; margin-top: 50px;">
      <p id="location"></p>
      <p id="weather"></p>
      <p id="temperature"></p><input type="button" class="btn btn-primary" onclick="farn()" value="ºF" id="F"><input type="button" class="btn btn-primary" onclick="cels()" value="ºC" id="C">
    </div>
    <div class="search-box">
      <input type="text" name="search" placeholder="Choose a location...">
      <button type="button" class="btn btn-primary" id="cityName">Search</button>
    </div>
  </body>
  <footer>Designed by João Cortez</footer>
</html>
              
            
!

CSS

              
                .top-nav {
  background-color: black;
  color: white;
  margin: 0;
  padding: 15px;
  text-align: left;
  font-family: 'Bungee Shade', cursive;
  font-size: 45px;
  
}

body {
  text-align: center;
  margin-top: 100px;
  background: url('http://i.giphy.com/Qs4CqRam8c5mU.gif') no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

.container-fluid {
  padding-top: 250px;
  font-size: 50px;
  font-family: 'Nova Square', cursive;
}

input[type=text] {
    width: 150px;
    -webkit-transition: width 0.4s ease-in-out;
    transition: width 0.4s ease-in-out;
    border-radius: 10px;
    border: 2px solid grey;
}

input[type=text]:focus {
    width: 20%;
    outline: none;
}

footer {
    text-align: center;
    margin-top: 100px;  
}

#location {
  font-family: 'Audiowide', cursive;
  border: 2px solid black;
  border-radius: 6px;
}

#F {
  background-color: orange;
  border: none;
}

#C {
  background-color: orange;
  border: none;
}

#cityName {
  background-color: orange;
  border: 2px solid white;
}
              
            
!

JS

              
                var base = "https://crossorigin.me/http://api.openweathermap.org/data/2.5/weather";
var lat = "";
var lon = "";
var APIkey = "&appid=5472513b95a7d0c54a7fa4aebcb48bf3";
var units = "&units=metric";
var api = "";
var city = "";
var weatherIcons;
var newTemperature;
var tempColor = "";

//using Geolocation part

function callGeoAPI() {
  api = base + lat + lon + APIkey + units;
  console.log(api);  
}

//for searching Weather using a City's Name

function callCityAPI() {
  api = base + city + APIkey + units;
  console.log(api);
}

$(document).ready(function() {

  function getOpenWeatherData() {
    //call OpenWeather api
    $.getJSON(api, function(data) {
      
      console.log(data);
      //update HTML with current temp and city name
      $('#temperature').html("<b>Temperature:</b> "+Math.round(data.main.temp) + '&deg;');
      $('#location').html(data.name);
      


      //button to convert C and F, it must have two functions
  $("#F").click(function() {
    $('#temperature').html("<b>Temperature:</b> "+(Math.round(data.main.temp)*(9/5)+32) + '&deg;');
  });

  $("#C").click(function() {
    $('#temperature').html("<b>Temperature:</b> " + Math.round(data.main.temp) + '&deg;');
    
  });





      //Icon

      var iconCode = data.weather[0].icon;
      var iconUrl = "http://openweathermap.org/img/w/" + iconCode + ".png";

      $("#weather").html("<b>Weather Status:</b> "+data.weather[0].description+"<img src='" + iconUrl  + "'>");
      });




 }
  
  //Get users Location info
   //Call the FreeGeoIP API for users IP info and then make call to OpenWeather API
      var freegeoIP = 'https://freegeoip.net/json/?callback';
      $.getJSON(freegeoIP, function(data) {
         lat += "?lat=" + data.latitude;
         lon += "&lon=" + data.longitude;
         console.log(lat, lon);
         callGeoAPI(); //set API call parameters
         getOpenWeatherData(); //Get information from API and update HTML
      });

      // Using the search button to search by City Name

    $('#cityName').click(function() {
    var cityName = $('input:text').val();
    city = "?q=" + cityName;
    console.log(city);
    callCityAPI();
    getOpenWeatherData();
  });
   
});
    

  
     
              
            
!
999px

Console