javascript - Function shows `undefined` in console -
this question has answer here:
- how return response asynchronous call? 24 answers
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 function runs, 2 things printed console:
undefined @ line xxxx
,xxxx
line of secondconsole.log()
.- the value
coordinatesobj
(an object containing address, latitude , longitude)
i want second console.log()
show value of coordinatesobj
.
what do?
without seeing markup, can't sure what's happening, code you've shown- suspect there no htmlinputelement element "address".
$("#invalidid").val(); // returns `undefined`
Comments
Post a Comment