First, you need to obtain the Google Maps API key from here.
Download Google Maps ActionScript 3.0 component from here
Next, copy the content in the zip package to the project/libs.
Let's take a look at the demo (
Right-click View Source or click here to view the source code):
The following is the complete code (or click here to view details ):
Download: Main. mxml
- <? XML version = "1.0" encoding = "UTF-8"?>
- <Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml"
- Layout = "vertical"
- Verticalalign = "Middle"
- Backgroundcolor = "white"
- Creationcomplete = "Init ();">
-
- <Mx: SCRIPT>
- <! [CDATA [
- Import com. Google. Maps. latlng;
- Import com. Google. Maps. Map;
- Import com. Google. Maps. mapevent;
- Import com. Google. Maps. Controls. maptypecontrol;
- Import com. Google. Maps. Controls. positioncontrol;
- Import com. Google. Maps. Controls. zoomcontrol;
- 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;
- Import MX. Events. resizeevent;
-
- Private var GoogleMap: map;
- Private var geocoder: clientgeocoder;
-
- Private function Init (): void {
- GoogleMap = new map ();
- GoogleMap. Key = app_id;
- GoogleMap. addeventlistener (mapevent. map_ready, googlemap_mapready );
- GoogleMap. setsize (new point (mapcontainer. Width, mapcontainer. Height ));
- GoogleMap. addcontrol (New zoomcontrol ());
- GoogleMap. addcontrol (New maptypecontrol ());
-
- Mapcontainer. addchild (GoogleMap );
- }
-
- Private function geocoder_geocodingsuccess (EVT: geocodingevent): void {
- VaR result: placemark = geocodingresponse (EVT. Response). placemarks [0];
- GoogleMap. setcenter (result. Point, 13 );
- }
-
- Private function geocoder_geocodingfailure (EVT: geocodingevent): void {
- Alert. Show ("unable to geocode address:" + EVT. Name );
- }
-
- Private function googlemap_mapready (EVT: mapevent): void {
- Geocoder = new clientgeocoder ();
- Geocoder. addeventlistener (geocodingevent. geocoding_success, geocoder_geocodingsuccess );
- Geocoder. addeventlistener (geocodingevent. geocoding_failure, geocoder_geocodingfailure );
- Geocoder. geocode (textinput. Text );
- }
-
- Private function button_click (EVT: mouseevent): void {
- Geocoder. geocode (textinput. Text );
- }
-
- Private function mapcontainer_resize (EVT: resizeevent): void {
- If (GoogleMap ){
- GoogleMap. setsize (new point (mapcontainer. Width, mapcontainer. Height ));
- }
- }
- ]>
- </MX: SCRIPT>
-
- <Mx: String id = "app_id" Source = "appid.txt"/>
-
- <Mx: applicationcontrolbar dock = "true">
- <Mx: Form stylename = "plain">
- <Mx: formitem label = "Address :"
- Direction = "horizontal">
- <Mx: textinput id = "textinput"
- TEXT = "601 Townsend St, San Francisco, CA 94103"/>
- <Mx: button id = "button"
- Label = "Submit"
- Click = "button_click (event);"/>
- </MX: formitem>
- </MX: Form>
- </MX: applicationcontrolbar>
-
- <Mx: uicomponent id = "mapcontainer"
- Width = "100%"
- Height = "100%"
- Resize = "mapcontainer_resize (event);"/>
-
- </MX: Application>