I have a function that gets the latLng from an adress with googles geocode.
function geoCode(address){
var geocoder = new google.maps.Geocoder;
geocoder.geocode({'address': address}, function(results, status) {
if (status === 'OK') {
var pos = {
lat:results[0].geometry.location.lat(),
lng:results[0].geometry.location.lng()
};
return pos;
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
When I console log the "pos" object in this function I get the positions, but when i try to console.log it in an other function for example the one below
function foo(){
var pos = geoCode(place);
console.log(pos.lat);
}
I get the following alert: TypeError: undefined is not an object (evaluating 'pos.lat')
There seems something wrong with the return of the pos object.