Why is my API not working?

So the link to the API is working for me when I open it in a window but for some reason it’s not working correctly in code and I can’t see why (or I don’t know why, it might just be something outside the my code I’m not aware of).

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    lon= position.coords.longitude;
    lat= position.coords.latitude;
    $("#data").html("latitude: " + lat + "<br>longitude: " + lon);

  var api= "https://fcc-weather-api.glitch.me/api/current?lat="+lat+"&lon="+lon;
  $.get.JSON(api, function(data){
    var weatherType = data.weather[0].description;
    var ktemp = data.main.temp;
    var wind = data.wind.speed;
    var city = data.name;

please somebody explain why it won’t recognize the API, or why it wont get anything from the JSON.

Please give us a link to your project so we can fully see everything that is going on.

Please do the following to help debug:

  1. Try running the api call without navigator geolocation. This will let you know if your api call isn’t working or is.
  2. Try the navigator geolocation to make sure you are getting the latitude and longitude correctly.

By isolating each of these, you can find out if your api call isn’t working or if your navigator geolocation isn’t working.

Please let us know once you confirm where the problem is, and also give us a link so we can test it ourselves. Thanks!

I’m having the same issue too. Our code looks pretty much the same.

Isn’t it .getJSON(api, [callback etc]) ?


Pack it up lads, Johnny Bizzle got it… I’m a fool who’s very new to this and added a ‘.’ to the .getJSON() function. Like a fool, a common fool.

(I put .get.JSON() for anybody wondering)

1 Like