GOOGLE MAP IN A FLASH APP

The Google Maps API for Flash  is used to add an interactive Google Maps to a website instead of using the JavaScript Maps API.  The advantage is that you can add additional Flash content to the map.

Download Goolge Maps API, API Key and Documentation

Go to http://code.google.com/apis/maps/documentation/flash and in the How do I start? section:

  1. Sign up for a Google Maps API Key to adhere to the licensing agreement  (If client's url is not available, use http://localhost)
  2. Download the Google Maps API for Flash SDK and unzip it to your desktop (or anywhere you prefer)
  3. Read the Developer's Guide for how to use the Google Maps APIs
  4. Read the API Reference on what the Google Maps API can do
  5. Join the announcements group to receive important updates

Install Google Maps Component

Add Code to Flash

// Import Google Maps libraries ====================================================================================
import com.google.maps.*;
import com.google.maps.overlays.*;
import com.google.maps.controls.*;

// Create a new instance of the Map class, assign it a key, and give it the same size as the Flash movie.
// Add EventListener and  blank function and then display it on screen

var map:Map = new Map();
map.key = "your_api_key";
map.setSize(new Point(stage.stageWidth, stage.stageHeight));
this.addChild(map);

// Add an addEventListener to "listen" for the map to be ready and then it will execute the event handler onMapReady.
map.addEventListener(MapEvent.MAP_READY, onMapReady);

function onMapReady(eventObject:MapEvent):void
{
map.addControl(new ZoomControl());
map.addControl(new MapTypeControl());
}

NOTE: Map controls include:

NOTE: The function passes an eventObject called MapEvent which is ignored in this case.
ALTERNATIVE: You may also initialize a map by intercepting and handling the MapEvent.MAP_PREINITIALIZE event instead, see MapOptions.

function onMapReady(eventObject:Event):void
{
map.addControl(new ZoomControl());
map.addControl(new MapTypeControl());
map.setCenter(new LatLng(37.77114, -122.40159), 18, MapType.NORMAL_MAP_TYPE);
}

Exporting SWF File

Output Flash movie as you normally would, but ensure that Local playback security: is set to Access network only so that the Flash player can communicate with Google's servers to retrieve the Maps API library.

Hosting Your SWF File in a Web Page

Normally,  the API Key is compiled with the Google Maps Flash SWF file and can be used as a standalone application. However, it is best practice to use FlashVars instead as an alternative. If values are specified as FlashVars, they will override values contained within the SWF file.  It is important to note that the API key must match the domain where the SWF file is hosted–not the domain where the HTML file may be hosted. Below is a snippet of code to include the FlashVars in the object and embed tags:

<object> ....
<param name=flashVars" value="key=your_api_key">
<embed ...
flashVars="key=your_api_key"
</embed.
</object>

BONUS: Add a custom marker

function onMapReady(eventObject:Event):void
{
map.addControl(new ZoomControl());
map.addControl(new MapTypeControl());
map.setCenter(new LatLng(37.77114, -122.40159), 18, MapType.SATELLITE_MAP_TYPE);
var my_marker:Marker = new Marker(new LatLng(37.77114, -122.40159) , new MarkerOptions( {icon:new marker()}));
map.addOverlay(my_marker)

}