cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="container">
  <div class="row">
    <header class="col-xs-12 text-center">
        <h1>Local Weather App</h1>
    </header>
    
    <div class="col-xs-8 col-xs-offset-2">
      <div class="text-center status">
        <p id="location" class="text-center"></p>
        <p id="weather" class="text-center">
          <span id="temp"></span> &#176;<span id="unit">C</span>
        </p>
        <p class="text-center"><button id="convertTemp" class="btn btn-default btn-primary">Change Temperature Metric</button>
        </p>
        <p id="icon" class="text-center"></p>
        <p id="summary" class="text-center"></p>
     </div>    
    </div>
  </div>
</div>

<!-- Footer -->
        <footer id="contact" class=" navbar-fixed-bottom container-fluid">
          <p class="text-center">Gaurav Shah</p>
            <div class="row">
                <div class="col-md-4 col-md-offset-4" >
                    <ul class="list-inline social-buttons">
                        <li><a href="https://www.linkedin.com/in/gauravshahtamu" target="_blank"><i class="fa fa-linkedin"></i></a>
                        </li>
                        <li><a href="https://github.com/gauravshah786" target="_blank"><i class="fa fa-github"></i></a>
                        </li>
                      <li><a href="https://freecodecamp.com/gauravshah786" target="_blank"><i class="fa fa-fire"></i></a>
                        </li>
                    </ul>
                </div>
            </div>
          <span id="credits">Powered by APIs : <a href="https://darksky.net/poweredby/">Dark Sky </a> & Google Reverse Geocoding</span>
        </footer>
            
          
!
            
              header {
  margin-bottom: 30px;
}
.status p {
  font-size: 1.8em;
  text-transform: capitalize;
}
h1 {
  font-size: 3em;
}

/* Footer */
footer {
    padding: 25px 0;
    text-align: center;
    background-color: #333;
    color: white;
}
.social-btns {
    position: absolute;
    top: 70%;
    left: 15%;
    font-size: 24px;
    padding: 10px;
}
.social-btns a {
    color: #fff;
    padding: 10px;
    -webkit-transition: all 0.3s;
    -moz-transition: all 0.3s;
    transition: all 0.3s;
}

ul.social-buttons {
    margin-bottom: 10;
}
ul.social-buttons li a {
    display: block;
    height: 40px;
    width: 40px;
    border-radius: 100%;
    font-size: 24px;
    line-height: 40px;
    color: white;
    outline: none;
    -webkit-transition: all 0.3s;
    -moz-transition: all 0.3s;
    transition: all 0.3s;
}
ul.social-buttons li a:hover,
ul.social-buttons li a:focus,
ul.social-buttons li a:active {
    background-color: #41C4AB;
}

            
          
!
            
              $(document).ready(function(){ 
    getWeather();
});

function getWeather(){
  //Getting current location's co-ordinates
  if (navigator.geolocation){
    navigator.geolocation.getCurrentPosition(function(position){
      var lat = position.coords.latitude;
      var long = position.coords.longitude;

      var darkSkyKey = "7c476095177ea70a6bf4d90baa398bb1";
      var corsURL = "https://cors-anywhere.herokuapp.com/"; // to avoid Access-Control-Allow-Origin (ACAO) 
      var darkSkyURL = "https://api.darksky.net/forecast/"; //Weather Forecast API URL
      var optionalParam = "?units=si";
      var weatherURL = corsURL + darkSkyURL + darkSkyKey+ "/"+ lat + "," + long + optionalParam;

      //get Weather JSON data 
      $.getJSON(weatherURL, showWeatherDetails);

      var fahrenheitTemp;
      var celsiusTemp;
      var showFahrenheit = false;

      //display Weather Data
      function showWeatherDetails(weatherJSON) {
        var weatherData = weatherJSON.currently;
        var temperature = parseInt(weatherData["temperature"]);
        console.log(temperature);
        fahrenheitTemp = Math.round(temperature);
        celsiusTemp = Math.round((temperature * 1.8) + 32);
        var icon = weatherData["icon"];
        var time = weatherData["time"];
        var summary = weatherData["summary"];
        $("#temp").html(fahrenheitTemp);
        $('#icon').html("<i class='wi wi-forecast-io-" + icon + "'></i>");
        $('#summary').html(summary);
      }
      
      // get Location from lat and long
      var googleKey = "AIzaSyDT5C67yEp1K0Ccn9mFv0eT3OLoghcyodM";
      var googleURL = "https://maps.googleapis.com/maps/api/geocode/json?latlng="; 
      var reverseGeocodingURL = googleURL + lat + "," + long + "&key=" + googleKey;
      
      $.getJSON(reverseGeocodingURL, function (reverseLocJSON) {
        var city;
        for (var i = 0; i < reverseLocJSON.results[0].address_components.length; i++) {
          var component = reverseLocJSON.results[0].address_components[i];
          if(component.types[0] == "locality") {
              city = component.long_name;
              $('#location').html(city);
          }
         }
      });

      //convert between temperature metrics
      $("#convertTemp").click(function(){
        showFahrenheit = !showFahrenheit;
        if (showFahrenheit) {
          $("#temp").html(celsiusTemp);
          $("#unit").html("F");
        } else {
          $("#temp").html(fahrenheitTemp);
          $("#unit").html("C");
        }
      });

    });
  }
}
            
          
!
999px
Loading ..................

Console