-
My problem is that my html is not being updated.
-
Also the “lat” and “lon” is being appended to the api string.
When I call console.log(api); inside getServerData(lat,lon)
api + "lat=" + lat + "&lon=" + lon;
console.log(api);
Console:
"https://fcc-weather-api.glitch.me/api/current?";
Primarily I’m trying to
- Divide all my functions to do one singular task
- Remove global variables
- I’m trying to keep my code clean, especially the (document).ready
$(document).ready(function() {
});
Below is the code
JavaScript:
$(document).ready(function(){
getCurrentLocation();
//getServerData();
});
function getServerData(lat,lon){
let api = "https://fcc-weather-api.glitch.me/api/current?";
api + "lat=" + lat + "&lon=" + lon;
console.log(api);
$.getJSON(api, function(serverResponse){
$("#location").html(serverResponse.name + ", " + serverResponse.sys.country);
$("#weatherIcon").attr("src",serverResponse.weather[0].icon);
$("#main").html(serverResponse.weather[0].main);
$("#description").html(serverResponse.weather[0].description);
$("#country").html(serverResponse.sys.country);
$("#temp").html(serverResponse.main.temp);
});
}
function getCurrentLocation(){
let lat,lon;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
getServerData(lat,lon);
});
}//if
}//getCurrentLocation
html:
<div class="container">
<p id="data"></p>
<p id="location"></p>
<span id="temp"></span><a href="">'C</a>
<p id="main"></p>
<img id="weatherIcon" src="" alt="">
</div>