Chuck, You can't return your referenceLatLng variable in the same function as you make the geocode request because it is asynchronous; you have to wait for an event from the geocoder. You can either dispatch an event of your own when the response comes in to tell the caller that the referenceLatLng is available (make class latlngGetter extend EventDispatcher), or pass a callback function to your initGetter function (making sure that if there is more than one caller, the appropriate callback is passed to the event handlers). All that said, if you are calling your latlngGetter class from only one place, I would just put the geocoder and event handlers right in there and avoid the extra events and object creation. Hope that helps.
helen On Aug 20, 2:08 pm, Chuck <[email protected]> wrote: > I'm trying to package a component in flex(using Actionscript) to > return a LatLng when passed an Address. Seems like a very simple > task, but the GeocodingEvent.GEOCODING_SUCCESS event is not responding > fast enough for the return variable... code below(simplified). I > sure I'm missing something simple(hopefully). Any help is very much > appreciated. > > Main application > ---------------------------------------- > .... load the mapping stuff > > var latlngGet:latlngGetter = new latlngGetter(); > var referenceLatLng:LatLng = latlngGet.initGetter("Some address"); > var ss:String = "LatLng of Reference: " + String(referenceLatLng); > Alert.show (ss); > --------------------------------------- > > component package/class > > latlngGetter.as > > package > { > import com.google.maps.LatLng; > import com.google.maps.services.ClientGeocoder; > import com.google.maps.services.GeocodingEvent; > import com.google.maps.services.GeocodingResponse; > import com.google.maps.services.Placemark; > import mx.controls.Alert; > public class latlngGetter > { > // Set up the geocoding variable > private var geocoder:ClientGeocoder; > // A variable for the reference point LatLng (public so it > can be > shared between functions) > public var referenceLatLng:LatLng; > public function latlngGetter() > { > // Nothing here in Constructor > } > > // This function takes the reference address and calculates the > LatLng returning it to the main function > public function initGetter(reference:String):LatLng { > > geocoder = new ClientGeocoder(); > geocoder.addEventListener > (GeocodingEvent.GEOCODING_SUCCESS,geocoder_geocodingSuccess); > geocoder.addEventListener(GeocodingEvent.GEOCODING_FAILURE, > geocoder_geocodingFailure); > geocoder.geocode(reference); > > return referenceLatLng; > } > > // geocoder Success Event > public function geocoder_geocodingSuccess > (evt:GeocodingEvent):void { > var result:Placemark = GeocodingResponse > (evt.response).placemarks[0]; > referenceLatLng = new LatLng(result.point.lat > (),result.point.lng()); > } > > // Geocoder unSuccessful Event > private function geocoder_geocodingFailure > (evt:GeocodingEvent):void { > Alert.show("Unable to geocode address: " + evt.name); > } > > } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API For Flash" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-maps-api-for-flash?hl=en -~----------~----~----~----~------~----~------~--~---
