1
2
3
4
5
6
7
8
9
10
11
12
var myvar;

geocoder.geocode({'latLng': latlng}, function(results, status) {
    // this callback is triggered when the geocoding function is done.
    // So, it's guaranteed that myvar is filled (unless there was some kind of error)
    myvar = results[1].formatted_address;
    console.log(myvar);
});

// the next line not guaranteed to work, since the geocoding function might not 
// have been finished when this line is processed, so, myvar could be empty.
console.log(myvar);