My code:
    function geocodeAddress(address){
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode(
            {
                'address':address   
            },
            function(results,status){
                if(status===google.maps.GeocoderStatus.OK){ 
                    var resultsObj = results[0].geometry;
                    var resultsLocationObj = resultsObj['location'];
                    var lat = resultsLocationObj['k'];
                    var lon = resultsLocationObj['D'];
                    var coordinatesObj = {
                        address : address,
                        latitude : lat,
                        longitude : lon
                    };
                    return coordinatesObj;
                }
            }
        );
    }
$(document).ready(function(){
function initialize(){
        $('#save-address').click(
            function saveAddress(){
                var addressText = $('#address').val();
                console.log(geocodeAddress(addressText));
            }
        );
}
    google.maps.event.addDomListener(window, 'load', initialize);
})
When the function runs, two things are printed to the console:
- undefined at line XXXX, where- XXXXis the line of the second- console.log().
- The value for coordinatesObj(an object containing the address, latitude and longitude)
I want the second console.log() to show the value of coordinatesObj.
What do I do?
 
    