The joke in here is that geoCode does not return anything, but it expects you to handle the map showing inside the function callback directly. You can right put it in console.log and do whatever, but not return and process out of the function.
Look for example https://developers.google.com/maps/documentation/javascript/examples/geocoding-simple and you'll see how this is true.
Edit:
Some workaround exists still, look at this code:
var geocoder;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(40.730885,-73.997383);
codeLatLng(function(addr){
alert(addr);
});
}
function codeLatLng(callback) {
var latlng = new google.maps.LatLng(40.730885,-73.997383);
if (geocoder) {
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
callback(results[1].formatted_address);
} else {
alert("No results found");
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}
}
The above code snippet tells how you can use explicit callback.
Source: How do I return a variable from Google Maps JavaScript geocoder callback?
Edit2:
Your code modified accordingly:
function getLatLong(address, callback){
var geo = new google.maps.Geocoder;
geo.geocode({'address':address, function(results, status){
if (status == google.maps.GeocoderStatus.OK) {
callback (results[0].geometry.location.k + ',' + results[0].geometry.location.D);
} else {
// do sth with error.
}
});
}
and calling it:
getLatLong(address, function(addr){
// do whatever with addr attribute
alert(addr);
});
Maybe that helps you get an idea.