Just started working on the weather app. It looks like this code is sending a request for the JSON but the lat and long variables come out as undefined.
var conditions;
var tempF;
var tempC;
var icon;
var lat;
var long;
var weather;
$(document).ready(function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
lat = position.coords.latitude;
long = position.coords.longitude;
});
}
$.getJSON(“https://api.darksky.net/forecast/556c1ca549a3ce16469d8670260c3a1d/” + lat + “,” + long,
function(data) {
conditions = data.currently.summary;
tempF = data.currently.temperature;
tempC = (tempF - 32) / 1.8;
icon = data.currently.icon;
});
weather = "The weather is ";
weather += conditions;
$("#input").html(weather);
});
error looks like:
api.darksky.net/forecast/556c1ca549a3ce16469d8670260c3a1d/undefined,undefined Failed to load resource: the server responded with a status of 400 (Bad Request)
Not sure why the code isn’t working?
My codepen is here: https://codepen.io/dkane47/pen/wePzqy