I’m building a weather app and so far so good But I ran into a trouble with getting a https to work properly: I tried to html
its content and geolocation data to an id
and nothing happens. I’m convinced that problem lies in my syntax because when I remove lat
and long
(which are vars
for current geolocation) and instead place numerical values of my location, it works. Thanks for help!
$(document).ready(function(){
// vars to store the data
var far;
var cel;
var inKelvin;
var long;
var lat;
//https for JSON + current geolocation
var apId = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + long + "&appid=5a58a57e6e275b561f89145e340eae23";
// grabbing geolocation
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
//declaration of var values
long = position.coords.longitude;
lat = position.coords.latitude;
});
}
$.getJSON(apId, function(data){
$("#app").html(apId);
// data for all of the math
inKelvin = data.main.temp;
var weat= data.weather[0].description;
var wind = data.wind.speed;
far = (inKelvin) * (9/5) - 459.67;
cel = (inKelvin) - 273.15;
});
});