Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
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;