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

              
                <div class = 'container-fluid text-center'>
    <!-- https://developers.google.com/maps/documentation/javascript/tutorial -->
            <div id="map-canvas"></div>
            <div class = 'block'>
                <h2>Your Local Weather</h2>
                <h3 id = 'location'>City, Country</h3>
                <div id = 'img'></div>
                <h3 id = 'temp'>--</h3>
                <a id = 'f' class = 'btn btn-primary'>F&deg</a>
                <a id = 'c' class = 'btn'>C&deg</a>
            <h4 id = 'description'>description</h3>
        </div>
            <div class = 'block'>
                <div class = 'row'>
                    <div class = 'col-sm-4'>
                        <h4 id = 'windSpeed'>windSpeed</h4>
                    </div>
                    <div class = 'col-sm-4'>
                        <h4 id = 'humidity'>Humidity</h4>
                    </div>
                    <div class = 'col-sm-4'>
                        <h4 id = 'precipitation'>Precipitation</h4>
                    </div>
                </div>
            </div>
            <div class = 'block'>
                <h4>7 Day Forecast</h4>
                <div id = 'forecast' class = 'row'></div>
            </div>
        </div>
              
            
!

CSS

              
                 body {
    background: url('https://images.freecreatives.com/wp-content/uploads/2016/02/Blue-Gradient-Blur-Background-For-Free.jpg') no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    color: white;
}

h1{
    background-color: black;
    width: 500px;
    margin: 20px auto;
    border-radius: 10px;
    opacity: .7;
}

.block{
    background-color: red;
    opacity: .7;
    width: 500px;
    height: auto;
    margin: 20px auto;
    border-radius: 20px;
    color: white;
}

h2{
    padding-top: 20px;
}

h4{
    padding: 5px;
}

.icon{
    width: 200px;
    height: 200px;
    color: white;
}

.forecast_icon{
    color: white;
    width: 50px;
    height: 50px;
}

.forecast_box{
    padding-left: 35px;
    padding-right: 35px;
}

#f, #c{
    margin-bottom: 20px;
}
              
            
!

JS

              
                $(document).ready(function() {
    //used in url to gain JSON data from DarkSky API
    var lon;
    var lat;

    //Farhenheit and Celsius temps
    var fTemp;
    var cTemp;

    //hold the icon type
    var icon;

    //all attributes that will be filled from API and displayed on page
    var humidity;
    var precipitation;
    var description;
    var windSpeed;
    var iconURL;
    var location;

    //used in 7 day forecast, stores high and low temp as well as icon type
    function Day(low, high, icon){
        this.low = low;
        this.high = high;
        this.icon = icon;
    };

    //Day objects will be pushed to this array
    var forecast = [];

    //stores the url's of each icon
    var background = {    "clear-day": "https://cdn4.iconfinder.com/data/icons/fitness-vol-2/48/65-512.png",
                          "clear-night": "https://cdn1.iconfinder.com/data/icons/weather-18/512/blue_sky_at_night-512.png",                               "partly-cloudy-day":"http://icons.iconarchive.com/icons/icons8/android/512/Weather-Partly-Cloudy-Day-icon.png",
                          "partly-cloudy-night": "http://icons.iconarchive.com/icons/icons8/android/512/Weather-Partly-Cloudy-Night-icon.png",
                          "cloudy": "https://image.flaticon.com/icons/png/512/51/51728.png",
                          "rain": "http://icons.iconarchive.com/icons/icons8/ios7/256/Weather-Little-Rain-icon.png",
                          "sleet": "http://icons.iconarchive.com/icons/icons8/windows-8/512/Weather-Sleet-icon.png",
                          "snow": "https://d30y9cdsu7xlg0.cloudfront.net/png/64-200.png",
                          "wind": "https://d30y9cdsu7xlg0.cloudfront.net/png/7702-200.png",
                          "fog": "https://cdn4.iconfinder.com/data/icons/wthr/32/659098-cloud-fog-512.png"}

    //if geolocation is found
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
        lat = position.coords.latitude;
        lon = position.coords.longitude;

        //concat lat and long values into api url
        var url =
            "https://api.darksky.net/forecast/24dad8747ac3e7a30ffcb8daada64f96/" +
            lat +
            "," +
            lon +
            "?callback=?";
          
          console.log(url);

        //url for the google location API
        var address_url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lon + "&key=AIzaSyBdnp8x3XrCjeJDlUJCMgI4zcfA_Zmm9Z0";

        //change location text
        $.getJSON(address_url, function(address_data) {
            location = address_data.results[4].formatted_address;
            $('#location').text(location);

        });

        $.getJSON(url, function(data) {
            fTemp = Math.round(data.currently.temperature);
            icon = data.currently.icon;
            description = data.currently.summary;
            windSpeed = data.currently.windSpeed;
            cTemp = Math.round((fTemp - 32) * (5/9));
            humidity = data.currently.humidity;
            precipitation = data.currently.precipProbability;

            for(var i = 0; i < 7; i++){
                var forecast_icon = data.daily.data[i+1].icon;
                var low = Math.round(data.daily.data[i+1].temperatureMin);
                var high = Math.round(data.daily.data[i+1].temperatureMax);

                for(var key in background){
                    if(key === forecast_icon){
                    forecast_icon = background[key];
                    }
                }

                var new_day = new Day(low, high, forecast_icon);

                forecast.push(new_day);
            }

            $('#f').click(function(){
                $('#f').addClass('btn-primary');
                $('#c').removeClass('btn-primary');
                $('#temp').text(fTemp + ' degrees');
            });

            $('#c').click(function(){
                $('#c').addClass('btn-primary');
                $('#f').removeClass('btn-primary');
                $('#temp').text(cTemp + ' degrees');
            });

            if($('#f').hasClass('btn-primary')){
                $('#temp').text(fTemp + ' degrees');
            }

            else{
                $('#temp').text(cTemp + ' degrees');
            }


            $('#windSpeed').text('Wind Speed: ' + windSpeed + ' mph' );
            $('#description').text(description);
            $('#humidity').text('Humidity: ' + humidity);
            $('#precipitation').text('Precipitation: ' + precipitation + '%');

            for(var key in background){
                if(key === icon){
                    iconURL = background[key];
                }
            }

            $('#img').append("<img src = '" + iconURL + "' class = 'icon'>");


            for(var j = 0; j < 7; j++){
              $('#forecast').append('<div class = "col-sm-1 forecast_box"><img src = ' + forecast[j].icon + ' class = "forecast_icon"><p>' + forecast[j].low + '/' + forecast[j].high + '</p></div>');
            }
        });
    });
    }

    else
        alert("No Geolocation found");
  
  
  // Styles for map
    // https://developers.google.com/maps/documentation/javascript/styling
    let styles = [

        // Hide Google's labels
        {
            featureType: "all",
            elementType: "labels",
            stylers: [
                {visibility: "off"}
            ]
        },

        // Hide roads
        {
            featureType: "road",
            elementType: "geometry",
            stylers: [
                {visibility: "off"}
            ]
        }

    ];

    // Options for map
    // https://developers.google.com/maps/documentation/javascript/reference#MapOptions
    let options = {
        center: {lat: 41.3184, lng: -72.9318}, // New Haven, CT
        disableDefaultUI: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        maxZoom: 14,
        panControl: true,
        styles: styles,
        zoom: 13,
        zoomControl: true
    };

    // Get DOM node in which map will be instantiated
    let canvas = $("#map-canvas").get(0);

    // Instantiate map
    map = new google.maps.Map(canvas, options);

    // Configure UI once Google Map is idle (i.e., loaded)
    google.maps.event.addListenerOnce(map, "idle", configure);



});

              
            
!
999px

Console