Help in console

Help in console
0

#1

Hi guys please help me out, my console screen is not printing my console outputs, here is the code : -
And i also wanted to know if i have used long and lat variables correctly in the api link or not ?

$(document).ready(function(){
  var long;
  var lat;
  var fTemp;
  var cTemp;
  if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
   long = position.coords.longitude;
    lat= position.coords.latitude;
   
  var api="http://samples.openweathermap.org/data/2.5/weather?lat='+lat+'&lon='+long+'&appid=bb77b854a0c13e495d0e46e97477b034";
  $.getJSON(api, function(data){
   
    var weatherType =data.weather[0].description;
    var kTemp = data.main.temp;
    var windspeed = data.wind.speed;
    var city = data.name;
     fTemp= (kTemp)*(9/5)-459.67;
    cTemp = kTemp-273;
  
    console.log(city);
    console.log(api);
});
});
  }
});

#2

You’re using an API that’s served over HTTP, which HTTPS apps don’t like. You can see an error in the console that says Blocked loading mixed active content "http://samples.openweathermap.org/...".

The quotation marks that you used in the URL are also inconsistent. You should change the single-quotes to double-quotes.

Try using this instead:
https://fcc-weather-api.glitch.me/


#3

hi so for this API i dont need an api key ?


#4

Yeah. You just need to plug in a latitude and longitude.


#5

Nice !!! so ill just plug in the long and lat variable in this and it will work !!


#6

Thank you very very much it works now !! :smiley:


#7

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#8

Thank you :smiley: ill keep in mind !