WeatherApp - not returning proper temperature

I’ve looked everywhere for a clue, or someone facing a similar problem as me. But I’ve found nothing; perhaps I don’t know what to properly search for.

Anyway, I apologize in advance if this has been asked already.

So, my code is returning a temperature. But it’s not in a proper format. For example, if it’s 30 degrees out, it’s returning something like “271.32”

Here is the code:

/***********************************************************
** This weather app made possible with the open-weather API: 
** https://openweathermap.org
************************************************************
** Images obtained for free at:
** https://www.pexels.com
************************************************************/

$(document).ready(function(){
  
  // Click event to rid the annoyance of the location request
  $('#getWeather').click(function() {
    var lat;
    var long;
    // Get user location 
    if (navigator.geolocation){
      navigator.geolocation.getCurrentPosition(function(position){
        // Display current location - might need to get rid of this

  // Returning the weather
   lat = position.coords.latitude;
   long = position.coords.longitude; 

  // When this code is published to codepen, github, etc.
  // use this URL in front of the api's URL:
  // https://cors-anywhere.herokuapp.com/

   // 'reaching out' to the API, and returning 'raw' JSON data
  $.getJSON("http://api.openweathermap.org/data/2.5/weather?lat=" +
                                                              lat +
                                                           "&lon="+
                                                             long +
                          "&APPID=919f297e735dd0af585e1f2a2318b499",
                          function(json) {                           
                            $("#town").html("<p><b>Location: </b></p>" +
                                      JSON.stringify(json.name));

                            $("#data").html("<p><b>Temperature: </b></p>" +
                                  JSON.stringify(Math.round(json.main.temp)));
                            /*$("#data").html("<p class='rise'>Temperature: </p>" +
                                    JSON.stringify(json.main.temp));*/
                           }, function(error){ 
                                console.log(error);
                              });

// $('#data').html("current temp: " + data.main.temp);
      
      });
    }
  });
});

Hi… perhaps you should have a better look at the api docs. I’m not 100% sure but i guess the default temp is coming in Kelvins.

Read the doc about units formatting in OpenWeatherMap Api Docs.

i think it’s something like units=[value] you need. :slight_smile:

Hi, imerljak. Thank you! I had no idea there was more documentation(didn’t bother scrolling all the way down)! Such a relief. Hopefully I’ll be able to figure this out now.

Thanks again!!!