Weather API using javascript

I think there’s some problem with the js code. Here’s code link:
Thanks in advance

You forgot to import jQuery. Your geolocation callback is also missing its position parameter.

would you explain to me about it. Any other sites, materials.

I can’t think of any site to explain with on top of my head… But I’m pretty sure MDN has articles about how to use geolocation.

When you have troubles with JS, one of the first things you’d want to do is open your browser’s console. Here’s what it might look like in Firefox:

Nevermind the first two messages (those have nothing to do with your code). The third one is more important. It says that $ is not defined. With that you can tell that somehow the jQuery library is not being used in your code. It can easily be fixed by adding jQuery in the JS settings (in the Quick-add dropdown).

After that you can run the page again. It should now ask you whether you want to give away your location. It actually works, but we hit another problem:


      lat = position.coords.latitude;
      lon = position.coords.longitude;

The code refers to some position variable (in the third and fourth lines above), but it’s not been defined anywhere. That’s why you get the second error message in the console.

The geolocation callback needs a parameter that will contain the position information. It should have been

                                               // over here!
navigator.geolocation.getCurrentPosition(function(position) {
  lat = position.coords.latitude;

Thanks for the help. I can’t figure how to make the font of all text of same font-family. Any ideas?

You should probably set the font styles in the body selector.

1 Like

@kevcomedia Thanks for the help.