I'm trying to build a pure JS weather application using the Geolocation API and the Dark Sky API. I'm very new to JavaScript but super willing to learn. I managed to get the user's position with the script provided on the MDN website. You can see my code here (I know JS code should be in a separate file—I'll change it when everything runs smoothly).
Here's my question: how can I call the Dark Sky API with user-specific latitude and longitude? I'm not sure how to write the XMLHttpRequest.
Here's an (excuse me in advance) attempt:
function getWeather() {
var xhr = new XMLHttpRequest();
xhr.open("GET","https://api.forecast.io/forecast/30e55c9dada04d2fd66fb43429ff2c51/" + lat + "," + long + ,false);
output.innerHTML = "<p>"xhr"</p>"
}
xhr.send();
I guess I have to put the getWeather function inside of the getPosition function because both the variables that interest me (lat, long) are defined locally. When I add the getWeather function inside of the script, getPosition doesn't run anymore and I'm not sure how to check whether the getWeather function call was successful.
Thanks for the help!