1

I want to get weather from OpenWeatherMap API based on latitude and longitude, but I'm getting error

net::ERR_CONNECTION_REFUSED

Project is on codepen.io

var appid = "myID";

function getLocation() {
  $.getJSON('https://geoip-db.com/json/geoip.php?jsonp=?') 
        .done (function(location)
        {
          $('.country').html(location.country_name);
          $('.city').html(location.city);
          var lat = location.latitude;
          var lon = location.longitude;
          var weatherLink = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=" + appid + "&callback=?";
          $('body').append(weatherLink);
          $.ajax({
              url: weatherLink,
              dataType: "jsonp",
              success: function(response) {
                  $('body').append(response);
              }
          });  
        });
}

$(document).ready(function() {
  getLocation();
});

I'm using https://geoip-db.com/ to get latitude and longitude. URL (weatherLink) is correct. Full error:

GET https://api.openweathermap.org/data/2.5/weather?lat=51.1&lon=17.0333&appid=…0b9873ed&callback=jQuery22406914555127333375_1469796455615&_=1469796455617 net::ERR_CONNECTION_REFUSED

4
  • thats a low level socket error. Commented Jul 29, 2016 at 12:56
  • And what can I do about it? Commented Jul 29, 2016 at 13:03
  • ask openweathermap, not here. Commented Jul 29, 2016 at 13:03
  • Ok then, but maybe I have some other error in code? here is codepen with full code: codepen.io/gkopowski/pen/JKBXxa Commented Jul 29, 2016 at 13:07

1 Answer 1

0

Your APPid is wrong, just sign up for an account and get a key from the site. You need a valid ID or it will refuse your connection.

http://openweathermap.org/appid#get

link me your codepen and I can take a closer look if you'd like.

Also, if you want to append the information from the site, you need to specify the parameters you want, otherwise your going to get a bunch of nonsense.

Sign up to request clarification or add additional context in comments.

5 Comments

I have valid ID, but I have changed it to "myID" to show my code. Here is codepen codepen.io/gkopowski/pen/JKBXxa
look again, there is an $.ajax call that produces error in console
try using getJSON instead, I had no problems when I did that challenge haha
sorry I can't be much more help, I tinkered around a bit but couldn't figure it out, I just thought you made a bonehead mistake with appID haha
its a little sloppy but here is my codepen if you need a reference, codepen.io/willcodes/pen/bZLWRo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.