I have 2 functions, function A calls function B which geocodes an address and returns the LatLng object back to function A but somehow, function A doesn't wait for function B to return result from Google.
function A() {
    var address = document.getElementById("txtbox").value;
    //geocoding here
    var here = B(address);
    if (here == null) {
        console.log("seems like geocode didn't work, defaulting value");
and in function B
function B(address) {
    var here;
    geocoder = new google.maps.Geocoder();
    geocoder.geocode( { 'address': address}, function(results, status) {
        console.log("geocoding");                                               
        if (status == google.maps.GeocoderStatus.OK) {
            console.log(results[0].geometry.location);
            currentlatlng = results[0].geometry.location;
            lng = currentlatlng.lng();
            lat = currentlatlng.lat();
            here = new google.maps.LatLng(lat, lng);
        } else {
            console.log("Geocode was not successful for the following reason: " + status);
        }
    });
    return here;
}
but seems like the output for the console is
seems like geocode didn't work, defaulting value
geocoding
hence, it seems like function A calls function B and then proceeds it..
i thought it would wait but then again as per my understanding of how google maps api work, it doesn't 'wait' per se, so what should i do?
 
     
     
    