GoogleMaps AS3 API (‘Hello World!’ example For FlexBuilder)
Google finally released an AS3 API for GoogleMaps (how cool is that). The Hello World example shown here is written in AS3 and intended to be compiled with the SDK's mxmlc compiler. Here is a quick code-conversion aimed squarely at Flex developers. Rather than extend Map we create an instance and add it as a child of a UIComponent instance.
You will need to register your own key and insert it in to the code at the appropriate point.
-
<?xml version="1.0" encoding="utf-8"?>
-
<mx:Application
-
xmlns:mx="http://www.adobe.com/2006/mxml"
-
width="800" height="600"
-
backgroundColor="#FFFFFF"
-
initialize="init()">
-
-
<mx:Script>
-
<![CDATA[
-
import com.google.maps.Map;
-
import com.google.maps.MapEvent;
-
import com.google.maps.MapType;
-
import com.google.maps.LatLng;
-
-
private var _map:Map;
-
-
private function init():void
-
{
-
_map = new Map();
-
_map.key = "your key here";
-
_map.addEventListener(MapEvent.MAP_READY, onMapReady);
-
_map.setSize( new Point (this.width, this.height))
-
mapContainer.addChild(_map);
-
}
-
-
private function onMapReady(event:MapEvent):void
-
{
-
_map.setCenter(new LatLng(40.736072,-73.992062), 14, MapType.NORMAL_MAP_TYPE);
-
}
-
]]>
-
</mx:Script>
-
-
<mx:UIComponent id="mapContainer" width="100%" height="100%"/>
-
</mx:Application>
Igor Costa created a nice little GoogleMap Flex component here which encapsulates much of the essential stuff :]
Edit: Haha, I got so excited I threw this together before reading on ... there is actually a Flex example already on the Hello World page near the bottom. Note that they also take advantage of the resize event.
2 comments
2 Comments so far
Leave a reply
[...] some of the basics for getting up and running with the new GoogleMaps AS3 API in Flex, with a Hello World example and an explanation of how to get rid of “Debug Mode” text / geocode when testing [...]
[...] GoogleMaps AS3 API (’Hello World!’ example For FlexBuilder) [...]