Hey everyone,
I have an issue with the concept of JavaScript that I don´t really understand.
[CODE]
var gloablx;
function doMapStuff(){
var address = “bla”;
var x;
geocoder(address, function(results){
addressLat1 = results[0].geometry.location.lat(); //Works
addressLng1 = results[0].geometry.location.lng(); //Works
x = addressLat1;
gloablx = addressLat1;
});
console.log(addressLat1); //NOT WORKING
console.log(x ); //NOT WORKING
console.log(gloablx ); //NOT WORKING
}
function geocoder(address, callback){
var geocoder = new google.maps.Geocoder();
geocoder.geocode({‘address’: address}, function (results, status){
if(status === google.maps.GeocoderStatus.OK){
console.log(results);
callback(results);
}else {
alert(‘Geocode was not successful for the following reason: ‘ + status);
}
});
}
I´m trying to use result of my geocoder function outside of the call (Don´t really know how to name this), but it isn´t working. I have also tried to use Prototypes, Getter & Setter etc., but I can´t get a value. What I´m doing wrong? How do I have to rewrite the code, to make this working? I hope someone can help me here ?
Best regards