0

i assigned place id here "placeid = results[0].place_id" but it dosen't. it returns me undefined. assignment operation fails there.

function match_up_dn(address)
{
    geocoder = new google.maps.Geocoder();
    var placeid;

    if (geocoder) 
    {
        geocoder.geocode({
            'address': address
        }, function (results, status) {

            if (status == google.maps.GeocoderStatus.OK) {
               console.log("al:-"+results[0].place_id);
                placeid = results[0].place_id;
            }
            else
            {
                alert("undefined address");
            }
        });
    }

    return placeid;
}
Mitul Lakhani
  • 182
  • 1
  • 12

1 Answers1

0

Try this

function match_up_dn(address)
{
    geocoder = new google.maps.Geocoder();
    var placeid;

        geocoder.geocode({
            'address': address
        }, function (results, status) {

            if (status == google.maps.GeocoderStatus.OK) {
               console.log("al:-"+results[0].place_id);
               placeid = results[0].place_id;
               return placeid;
            }
            else
            {
                alert("undefined address");
            }
        });

}
Raj Suvariya
  • 249
  • 1
  • 4
  • 14
  • @MitulLakhani Try now this will definitely work. – Raj Suvariya Jun 08 '16 at 06:42
  • Exactly you were not getting output because API call response functions run on background thread so main thread will return null before background thread update the value. Now as you move return statement to background thread it will solve your problem – Raj Suvariya Jun 08 '16 at 06:44
  • it's works this way. **match_dn(document.getElementById('recipient-address').value);** Not this way **else if(Origin_postal == match_dn(document.getElementById('recipient-address').value))** – Mitul Lakhani Jun 09 '16 at 09:05