Values Not Reflecting Weather In My Area?

This is my code:

I’m curious about how the API works. I manually set the lat and long for my location (toronto) and it says the temperature is 23 but without any units. It’s definately not 23 celcius or fahrenheit here so I’m a little bit confused as to what the lat and long input actually does. Or how I change it to display values for my area. Thanks!

API works like this --> var api = "https://fcc-weather-api.glitch.me/api/current?lat=" + lat + "&lon=" + lon;

How do you get lon and lat?

https://www.freecodecamp.org/challenges/get-geolocation-data

How come my latitude and longitude isn’t changing though? It still shows Lat:35, Long: 139…Also the temperature is not reflecting the temperature at my location (toronto). I find some times when i refresh, it shows 35 and 139 and other times it shows 43 -79

What browser are you using?

@John-freeCodeCamp i am using google chrome for this

Same here. I have no idea why its not working.

Try running this code in your at the top of your js section in codepen and check the console -->

$(document ).ready(function() {
  navigator.geolocation.getCurrentPosition(function(position) {
    console.log( position.coords.latitude, position.coords.longitude)
     });
  });

I did it, and got the correct lon and lat.

Make sure $(document ).ready(function() { }); covers everything.

Here is what i did for my project

$(document).ready(function() {
  var lon;
  var lat;
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      lon = position.coords.longitude;
      lat = position.coords.latitude;
      var api =
        "https://fcc-weather-api.glitch.me/api/current?lat=" +
        lat +
        "&lon=" +
        lon;
      $.getJSON(api, function(data) {
             // code
            });
        });
     }
});

If this doesn’t work, create another forum post asking why lat and lon is wrong.

Alright it seems to work in firefox, does that narrow the problem down at all?

Does the code i listed above work on chrome. The one i did for my project?

Give all the code you test at least 20 seconds.

just updated it, still doesn’t seem to work :confused: It’s weird how it only seems to work some times. Like maybe 1/50 refreshes but on fox it seems to work more frequently. Still not 100% of the time though…

Create a separate forum post on why your not getting the right lon and lat.

@camperextraordinaire might be able to help