Welcome to the Treehouse Community
Looking to learn something new?
Devon Stanton7,793 Points
How do I change the temperature metric
I've gone with the other weather api. and it had the following to say in the documentation
full documentation: https://openweathermap.org/current#current_JSON
"main.temp Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit."
However even if I do that it wouldn't affect the values I'd just be changing the unit and not the actual temperature to reflect the unit.
Neil McPartlin14,662 Points
Devon, if you scroll down the link you provided to 'Units format', it explains that you just need to add
&units=metric onto the end of your API call.
Charlie Gallentine12,092 Points
When I have used openweathermap in the past, I have assigned the temperature to a variable and done the conversions to the variable to get it to different units. Sorry that it doesn't necessarily answer your question but it is a solution that I have found works!
I'm also not sure that I'm understanding your question entirely, but this should update all of the variables to have the right value each time a call is made to the API using $.getJSON() or comparable methods.
// Get the temperature from the API in units of Kelvin temperatureKelvin = main.temp; // Convert the temperature from Kelvin to degrees Celsius temperatureCelsius = temperatureKelvin + 273.15; // Convert the temperature from degrees Celsius to degrees Fahrenheit temperatureFahrenheit = temperatureCelsius * 1.8 +32;