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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBVyTOJOmO7wkr0b4iq8uoNl7EPsdzzZ54&libraries=places"></script>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>

<h1 class="text-center">Weather Application</h1>
<br>
<span class="underline-from-center">
<input id="city" type="text" class="text-center " placeholder="Enter Location"></input> 
</span><br>

<button id="sear" class="change">  search
</button>

 <div class="display col">
  </div>
<div id="weatherBox">
  <br>
  <h2 id="result2"></h2>
 <h3 id="result"></h3>
  <img id="ic" align="middle">
 <h3 id="result3"></h2>
  
  <div id="container">
    <button id="showTemp"><b>°C</b></button>
    <button id="fah"><b>°F</b></button>
</div>
  <h2>For Weather Forecast</h2>
  <a href="https://breenbo.github.io/weather_app/" target="blank"><h3> Click Here</h3></a>

</div>
  <hr>
<h4 class="text-center">Written and coded by:Shweta Rajput</h4>

              
            
!

CSS

              
                .text-center{
  text-align:center;
}
#showTemp,#fah{
  background-color:rgba(100,10,40,00);
  border-radius:100px;
   display:inline-block;
  width:40px;
  height:40px;
  margin:20px;
}

#container{
  text-align:center;
}
#weatherBox{
  border:10px solid rgba(100,10,89,190);
  height:440px;
  width:800px;
 margin:auto;
   border-radius:95px;
}
h2{
  text-align:center;
  font-stle:oblique;
  font-family:verdana;
 }
#ic{
 width:80px;
  height:80px;
  margin:auto;
  display:block;
}
body{
  background-image:url("https://i.ytimg.com/vi/4kfXjatgeEU/maxresdefault.jpg");
  background-repeat:no-repeat;
  background-size:cover;
}
h3{
  text-align:center;
  font-style:oblique;
  font-family:sans-serif;
  }
h1{
  font-family: Helvetica;
  font-size:40px;
}
#city{
 position:absolute;
   border-radius:8px;
   height:22px;
  width:200px;
left:530px;
  top:80px;
  font-size:18px;
  font-family:sans-serif;
     }
#sear{
  position:absolute;
 right:480px;
  padding:5px;
  width:58px;
  height:28px;
  border-radius:5px;
  background-color:#0bb5ff;
  font-size:15px;
  color:white;
  top:80px;
  padding:2px;
  border:2px solid #555555;
  }
#sear:active{
  transform: translateY(4px);
}



              
            
!

JS

              
                $(document).ready(function(){
  var lon,lat,api_url,item,api_url2;
 $("#sear").on('click',function(){
    item=$("#city").val();
      api_url='https://cors-anywhere.herokuapp.com/http://api.openweathermap.org/data/2.5/weather?q='+item+' &units=metric&appid=1aca79eb47f4808390fc328bce65e727';
api_url2='api.openweathermap.org/data/2.5/forecast?q='+item+' &units=metric&appid=1aca79eb47f4808390fc328bce65e727';
$.ajax({
          url : api_url,
          method : 'GET',
          success : function (data) {
            var tempr = data.main.temp;
    var wear=data.weather[0].description;
              $('#result2').text(data.name+","+data.sys.country);
          
       
            var   icon=data.weather[0].icon;
            
   $('#result').text(tempr +'°C');
        $('#result3').text(wear.toUpperCase());
            $("#ic").attr('src',"https://openweathermap.org/img/w/"+icon+'.png');
       
             $("#fah").on('click',function(){
  
 var te=tempr* (9/5)+32; 
               $('#result').text(te.toFixed(2) +'°F')
    });
            $("#showTemp").on('click',function(){
     $('#result').text(tempr+'°C');
     });
       
          }
        });
  });
    if(navigator.geolocation)
 {
    navigator.geolocation.getCurrentPosition(gotLocation);
    function gotLocation(position){
    lat=position.coords.latitude;       
    lon=position.coords.longitude;             
    console.log(position);  api_url='https://cors-anywhere.herokuapp.com/http://api.openweathermap.org/data/2.5/weather?lat='+lat+'&lon='+lon+'&units=metric&appid=1aca79eb47f4808390fc328bce65e727';

$.ajax({
          url : api_url,
          method : 'GET',
          success : function (data) {
            var tempr = data.main.temp;
    var wear=data.weather[0].description;
            var cit=data.name;
           
            var   icon=data.weather[0].icon;
            
            $('#result2').text(cit);
   $('#result').text(tempr +'°C');
            $('#result3').text(wear.toUpperCase());
            $("#ic").attr('src',"https://openweathermap.org/img/w/"+icon+'.png');
       
             $("#fah").on('click',function(){
  
 var te=tempr*(9/5)+32; 
               $('#result').text(te.toFixed(2) +'°F')
    });
            $("#showTemp").on('click',function(){
     $('#result').text(tempr+'°C');
     });
       
          }
        });
      }
       
      
 } 
else{
  alert("geolocation can't be accessed");
}   
  
  
});

//new
/*Deletes city text and allows for new city*/
$(document).on('click', ".change", function() {
  var name = "Enter City Name";
  $("#city").attr("placeholder", name);
  $("#city").val('');
  $("#city").focus();
  $(this).addClass("inProgress");
  $(this).html("update");
  $(".underline-from-center").addClass("now");
});

// This section displays a dropdown for user-entered locations using the Google Places API
// This location is then used to get coordinates to find weather for that location
  
$('#city').on('focus', function() {
  geolocate();
})
  
var placeSearch, autocomplete;

/*new autocomplete object, searches only cities*/
function initialize() {
  autocomplete = new google.maps.places.Autocomplete((document.getElementById('city')), {
    types: ['(cities)']
  });
  /*google.maps.event.addListener(autocomplete, 'place_changed', function() {
    fillInAddress();
  });*/
}
  
/*sets lat and long to new location*/
function setNewLocation() {
  var place = autocomplete.getPlace();
  
  lat = place.geometry.location.lat();
  lon = place.geometry.location.lng();
  if((place.address_components[0].short_name).length < 4){
    city =  place.address_components[0].long_name;
  } else {
    city =  place.address_components[0].short_name;
  }
  console.log(city);
  
}

/*Gets geographical location to prepopulate the autocomplete object*/
function geolocate() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position){
      var geolocation = new google.mapsLatLng(position.coords.latitude, position.coords.longitude);
      
      autocomplete.setBounds(new google.maps.LatLngBounds(geolocation, geolocation));
      
    });
  }
}
  
initialize();



              
            
!
999px

Console