javascript - Function shows `undefined` in console -


this question has answer here:

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:

  1. undefined @ line xxxx, xxxx line of second console.log().
  2. 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

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -