I'm working on how to push the value of a variable outside a json function. I'm integrating Google maps and Instagram's API together so I'm passing the longitude and latitude coordinates to glat and glng to var url (which is outside the google function. Currently I'm using PHP and not really familiar with json.
var glat;
var glng;
//Google maps latitude and coordinates
$.getJSON(mapurl, function(google){
glat = google.results[0].geometry.location.lat;
glng = google.results[0].geometry.location.lng;
console.log('<?php echo urlencode($_GET['location']);?>');
console.log(glat);
console.log(glng);
//return glat;
});
var url = "https://api.instagram.com/v1/media/search?lat=" + glat + "&lng=" + glng + "&distance=1000&client_id=<?php echo $client_id; ?>&count=40&callback=?";
//This pulls the instagram images
console.log(url);
//Instagram Feed
$.getJSON(url, function (response) {
//http://techmonks.net/instagram-using-the-api/
for(var i = 0; i < 40; i++){
$("#feed ul").append("<li><a target='_blank' href='"+response.data[i].link +"'><img src='"+response.data[i].images.low_resolution.url+"'/></a></li>");
}
});