I'm trying to get the longitude and latitude I called in via ajax into their own variables so that I can use them in the request I'm going to make the the DarkSky API. I'm aware of them being local, and so can't be accessed outside of the ajax function, but I can't for the life of me work out a way around it. Here's my code:
$(document).ready(function() {
//location API
$("#myweather").load("window",function() {
$("#location").fadeOut(function() {
$.ajax({
async: false,
url: "https://geoip-db.com/jsonp",
jsonpCallback: "callback",
dataType: "jsonp",
success: function(loc) {
$("#location").html(loc.city)
var long = loc.longitude
var lat = loc.latitude
}
});
}).fadeIn();
});
$("#result").load("location", function() {
$("#result").fadeIn(function() {
$.getJSON("https://api.darksky.net/forecast/15f8bf5641489ec32f66662221933c14/" + lat + long, function(forecast) {
consolelog(forecast);
});
});
});
});