On Oct 4, 11:43 am, Andy Newby <
andy.ne...@gmail.com> wrote:
> Hi,
>
> I'm trying to get a basic geocoder working, but can't seem to get the values
> passed back. The main codes are:
>
>
> function codeAddress(address) {
> geocoder.geocode( { 'address': address}, function(results, status) {
> if (status == google.maps.GeocoderStatus.OK) {
> var test = results[0].geometry.location.lat() + "," +
> results[0].geometry.location.lng();
> alert("TEST: " + test);
> } else {
> alert("Geocode was not successful for the following reason: " +
> status);
> }
> });
> }
>
> The part:
>
> alert("TEST: " + test);
>
> prints out the value I'm expecting fine:
>
> TEST: 51.089816,-0.44929000000001906
>
> ..yet the values here are undef:
>
> var lat_lng_vals = codeAddress("Rudgwick, UK");
> alert("LAt: " + lat_lng_vals);
>
> What am I doing wrong? FF debugger doesn't show any errors, but it never
> seems to get the values? Does it maybe need running using async?
Geocoding is asynchronous. You can't return the results that way, you
need to use them in the callback function.
-- Larry