Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Javascript callback scope issue

600830May 13 2009 — edited May 13 2009
Hi,
I'm using the Google maps geocoder to get latitudinal and longitudinal coordinates from a passed in address.
The callback function getGeocode() is returning the coordinates and saved into the local variable 'point'.

The issue I'm having is the point value is not seen outside of getGeocode function even
though the local variable 'point' is global to the function.

I was hoping to return the local variable point from the getAddrs() function. How can I get the variable 'point' passed back from
the function getAddrs().

From Firefox console.log, both 'apoint' and 'cpoint' is undefined. 'bpoint' has the coordinates (-32.829,116.32222).

I'm using it like so:

var address = "1010 Blossom Lane,Spring Valley,CA"

var apoint = getAddrs(address);

console.log('apoint: %s', point);
function getAddrs(address)
{
      var point;

      // Create new geocoding object
      geocoder = new GClientGeocoder();

      if (address != '')
      {
        // Retrieve location information, pass it to getGeocode()
       geocoder.getLocations(address,getGeocode);
      }

      
     //Get Latitude and Longitude
     function getGeocode(response)
     {
      
      // Retrieve the object
      place = response.Placemark[0];

      // Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
                          place.Point.coordinates[0]);

      console.log('bpoint: %s', point);
     
     
      }
      console.log('cpoint: %s', point);

      return point;
     
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 10 2009
Added on May 13 2009
2 comments
432 views