Disclaimer:
I edited this post because another error occured after I switched from an API that did not support CORS to another API.
I am currently trying to build an app on codepen.io that displays the local weather based on the data from the geolocation of the user. I am using this API provided by OpenWeatherMap. The editor didn't show any syntax errors and I couldn't find one neither, so I assume I made a logical mistake in the AJAX request. I would really appreciate if someone could tell me where I went wrong:
if (navigator.geolocation) {
window.onload = function(){
var currentPosition;
function getCurrentLocation (position) {
currentPosition = position;
var lat = currentPosition.coords.latitude;
var long = currentPosition.coords.longitude;
$.getJSON('api.openweathermap.org/data/2.5/weather?lat=' + lat + '&lon=' + long + "&appid=81621bf2bb3e08f0bfd40540baafb8ee", function(data) {
$('#info').append('<p>' + data.weather[0].description + '</p>');
});
};
};
navigator.geolocation.getCurrentPosition(getCurrentLocation);
}
<div class="main">
<div align="center" id="info"></div>
</div>
I only provided the code I found relevant, but if you need the whole code you can follow the first link I included above.
Thanks for your advice and taking your time in advance :)