The console.log is giving an undefined value of the coord. If we console.log coord inside the if function, it gives the value, but it seems like the values cannot be coming out from the geocode function.
Does anyone know what the scope of geocode is and how can I change to get the values out from the geocode function?
THANKS
var coord;
function change_coord(location) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': location}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//real_lat and real_lng are int values
var real_lat = results[0].geometry.location.lat();
var real_lng = results[0].geometry.location.lng();
coord = {lat: real_lat, lng: real_lng};
}
});
console.log(coord); //undefined
}