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
-~----------~----~----~----~------~----~------~--~---