====EDIT=====
I managed to solve my problem by moving the AJAX request into the geolocation request
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
userLat = "lat=" + position.coords.latitude;
userLon = "&lon=" + position.coords.longitude;
api = 'https://fcc-weather-api.glitch.me/api/current?' + userLat + userLon;
// =========AJAX REQUEST
$.getJSON(api, function(json){
console.log(json);
$('#data').html(JSON.stringify(json));
});
});
}
I can’t figure out how to send the request with valid values, as the numbers will convert from float into string when sending.
What should I change?
here’s my code:
<script>
// ====NAMES FOR LATTITUDE AND LONGITUDE
var userLat;
var userLon;
// ====SET LAT AND LON TO CURRENT GEOPOSITION COORDINATES
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
userLat = "lat=" + position.coords.latitude;
userLon = "&lon=" + position.coords.longitude;
});
} else {
// PROMPT NO SUPPORT
}
// =========AJAX REQUEST
var api = 'https://fcc-weather-api.glitch.me/api/current?' + userLat + userLon;
$.getJSON(api, function(json){
console.log(json);
$("#data").html(json);
});
// Only change code above this line.
</script>
<div id = "data">
<h4>You are here:</h4>
</div>