Weather App not working

  var lon;
  var lat;

  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= ""+lon+"&lat=:"+lat; 
      $.getJSON(api, function(data) {
        var temp = ""; 
        temp += data.main.temp;

Can anyone tell why my project is not working?

I’ve edited your post for readability. When you enter a code block into the forum, 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.


The first thing that I notice is that your weather url:


… has colons. It should be:


I think you done some minor mistakes in your code. It should be:




Still it is not working.

You’re going to have to be more specific. Show us the code that you have now. Tell us what you expect it to do. Tell us what it is actually doing.

The better quality the question, the better quality the answer.
This is my code. It is only showing lat and lon but it should have shown temp also.

instead of

It worked. Thankyou all.