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

              
                <ul class="nav nav-tabs">
  <li class="nav active"><a data-toggle="tab" href="#weatherPanel" onclick="geoWeather()">Show my weather</a></li>
  <li class="nav "><a data-toggle="tab" href="#loc" onclick="geoFindMe()">Show my location</a></li>
</ul>
<div class="container tab-content">
  <div class="tab-pane fade" id="loc"></div>
  <div class="tab-pane fade in active" id="weatherPanel">
  </div>
</div>
  <label for="zip">Feel free to enter a zip code</label>
  <input name="zip" type="text" id="zip"  required/>  
  <br/>
  <label for="zip">and country code</label>  
  <input name="country" value="us" type="text" id="country" required/>
  <button type="button" onclick="changeZip()">Submit</button>
              
            
!

CSS

              
                body {
  padding: 20px;
  background-color: #ccccda;
  color: #aaaaaa;
  text-align: center;
}

.container {
  text-align: center;
  margin-top: 5%;
  width: 80%;
  padding: 0 10%
}

a {
  text-decoration: none;
  color: white;
  &:hover {
    text-decoration: none;
    color: gray;
  }
}

#weatherPanel {
  display: flex;
  flex-flow: column;
  margin: 0 auto;
  border: solid;
  width: 36em;
  background-color: white;
  height: 50rem;
}

#weatherPanel h1 {
  font-family: "Gill Sans Extrabold", Helvetica, sans-serif;
  font-weight: bold;
  font-size: 4em;
  color: gray;
  flex-wrap: wrap;
}

.wi {
  display: block;
  font-size: 15rem;
  text-align: center;
  margin: 5rem 0%;
}

#temp {
  display: flex;
  font-size: 3em;
  justify-content: space-between;
}

#tempButton {
  margin: 0 auto;
  justify-content: center;
  border: none;
  background: white;
  color: gray;
  padding: 1em 2em;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 1em;
  text-shadow: 0 0 3em #000;
}

#loc img {
  height: 50rem;
  width: 50rem;
  margin-bottom: -30em;
}
              
            
!

JS

              
                let latitude;
let longitude;
let zipcode = -1;
let country = "";
let city;
let tempC;
let tempF;
let isCurrentTempF = 1;

$.getJSON('//freegeoip.net/json/?callback=?', function(data) {
  latitude = data.latitude;
  longitude = data.longitude;

  geoFindMe();
});

function geoFindMe() {
  const output = document.getElementById("loc");
  if (typeof position !== 'undefined' && typeof latitude === 'undefined' & typeof longitude === 'undefined') {
    console.log(position);
    latitude = position.coords.latitude;
    longitude = position.coords.longitude;
  } else {

  }
  console.log(latitude);
  $.getJSON('http://nominatim.openstreetmap.org/reverse?format=json&lat=' + latitude + '&lon=' + longitude + '&zoom=18&addressdetails=1',
    function(position) {
      if (typeof city !== 'undefined') {
        output.innerHTML = '<h1>' + city + '</h1>'
      } else {
        output.innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>';
      }

      let img = new Image();
      img.src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=13&size=500x450&sensor=false";
      img.style.maxwidth = '90%';

      output.appendChild(img);
    });
}

const zipRequest = 'http://nominatim.openstreetmap.org/search?postalcode=' + zipcode + 'format=json&&zoom=18&addressdetails=1';

const weather = document.getElementById('weatherPanel');

function geoWeather() {
  if(zipcode > 0) {
    
  $.getJSON('http://api.openweathermap.org/data/2.5/weather?zip='+zipcode+','+country+'&APPID=e507d5f4567ff3cfd70ce5ec38686601',
    function(data2) {
    latitude = data2.coord.lat;
    longitude = data2.coord.lon;
      tempC = Math.round((data2.main.temp - 273.15) * 10) / 10;
      tempF = Math.round(((tempC * 9 / 5) + 32) * 100) / 100;
      weather.innerHTML = "<h1>" + data2.weather["0"].description + "</h1> <i id='weatherIcon' class='wi wi-owm-" + data2.weather["0"].id + "'></i><div id='temp'><button class='button' id='tempButton' onClick='changeTemp()'>" + tempF + "°F</button></div>";

      let wi = document.getElementById("weatherIcon");
      if (tempC < 15) {
        wi.style.color = "#A5F2F3";
      } else if (tempC < 30) {
        wi.style.color = "#F9FA57";
      } else {
        wi.style.color = "#F00";
      }
    geoFindMe();
    });
  }
  else {
    
  $.getJSON('http://api.openweathermap.org/data/2.5/weather?lat=' + latitude + '&lon=' + longitude + '&APPID=e507d5f4567ff3cfd70ce5ec38686601',
    function(data) {
      tempC = Math.round((data.main.temp - 273.15) * 10) / 10;
      tempF = Math.round(((tempC * 9 / 5) + 32) * 100) / 100;
      weather.innerHTML = "<h1>" + data.weather["0"].description + "</h1> <i id='weatherIcon' class='wi wi-owm-" + data.weather["0"].id + "'></i><div id='temp'><button class='button' id='tempButton' onClick='changeTemp()'>" + tempF + "°F</button></div>";

      let wi = document.getElementById("weatherIcon");
      if (tempC < 15) {
        wi.style.color = "#A5F2F3";
      } else if (tempC < 30) {
        wi.style.color = "#F9FA57";
      } else {
        wi.style.color = "#F00";
      }
    });
  }
}

function changeTemp() {
  const tempBox = document.getElementById("temp");
  if (isCurrentTempF) {
    tempBox.innerHTML = "<button class='button' id='tempButton' onClick='changeTemp()'>" + tempC + "°C</button>";
  } else {
    tempBox.innerHTML = "<button class='button' id='tempButton' onClick='changeTemp()'>" + tempF + "°F</button>";
  }
  isCurrentTempF = !isCurrentTempF;
}

function changeZip() {
  zipcode = document.getElementById("zip").value;
  country = document.getElementById("country").value;
  
  geoWeather();
}
              
            
!
999px

Console