1

I am trying to get the values of longitude and latitude in to an array..

 function codeAddress(address) {
    var place;
    var lines=[];

    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);

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

      place=results[0].geometry.location;
str=place.lng();
        lines.push(place.lng());
        lines.push(place.lat());

         });
    console.log(lines);
    console.log(lines.length);

    return lines;
  }

but lines.length is shown as zero.. when i try to print the array lines, when i check it using firebug, it shows empty array [] bt when i try click on the [], it shows opens and shows

[]
0    1.32323
1    125.12323

i'm not sure what is wrong..

when i try to console.log(results[0].geometry.location) it shows R { ib=1.32323, jb=125.12323, toString=function(), more...}

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1371896
  • 2,192
  • 7
  • 23
  • 32
  • 1
    Geocoding is asynchronous. You have to use the data in the callback function (when it is available), you can't return it from the function. – geocodezip Mar 06 '13 at 17:06
  • so can research the post http://stackoverflow.com/questions/2993563/how-do-i-return-a-variable-from-google-maps-javascript-geocoder-callback – Дария Печайко Mar 06 '13 at 17:58

0 Answers0