var hhhhhhh = '';
function displayLocation(latitude, longitude) {
var request = new XMLHttpRequest();
var method = 'GET';
var url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=' + latitude + ',' + longitude + '&sensor=true';
var async = true;
request.open(method, url, async);
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
var data = JSON.parse(request.responseText);
var addressComponents = data.results[0].address_components;
for (i = 3; i < 4; i++) {
hhhhhhh = addressComponents[i].long_name;
}
}
};
request.send();
}
console.log(hhhhhhh);
var hhhhhhh is not getting any value out of displayLocation function. In console,outside the function its null while inside the function its getting its value. Please Help.thank you