GoogleMaps API – SimpleDemo

Posted on January 12, 2009
Filed Under Actionscript 3.0, experiments, Opensource | Comments Off

experiment_gm_v001

Simple demo showing google maps in flash, add a marker as an overlay with a listener to open its information window. (Up at codexperiments.googlecode.com).

  1. package
  2. {
  3.  // flash
  4.  import flash.geom.Point;
  5.  import flash.events.Event;
  6.  import flash.display.MovieClip;
  7.  
  8.  // google maps
  9.  import com.google.maps.Map;
  10.  import com.google.maps.MapEvent;
  11.  import com.google.maps.MapType;
  12.  import com.google.maps.LatLng;
  13.  import com.google.maps.InfoWindowOptions;
  14.  import com.google.maps.MapOptions;
  15.  import com.google.maps.overlays.Marker;
  16.  import com.google.maps.MapMouseEvent;
  17.  import com.google.maps.controls.NavigationControl;
  18. import com.google.maps.controls.MapTypeControl;
  19.  
  20.  public class ShowMapsDemo extends MovieClip
  21.  {
  22.   private var _map:Map;
  23.   private var _marker:Marker;
  24.  
  25.   public function ShowMapsDemo()
  26.   {
  27.    addEventListener(Event.ADDED_TO_STAGE, initialize);
  28.   }
  29.  
  30.   private function initialize(event:Event):void
  31.   {
  32.    removeEventListener(Event.ADDED_TO_STAGE, initialize);
  33.  
  34.    // setup google map
  35.    _map = new Map();
  36.  
  37.    // place your own googlemaps api key at:http://code.google.com/apis/maps/signup.html
  38.    _map.key = "your googlemaps api key goes here";
  39.    _map.setSize(new Point(550, 400));
  40.    _map.addEventListener(MapEvent.MAP_PREINITIALIZE, mapPreInitializeHandler);
  41.    _map.addEventListener(MapEvent.MAP_READY, mapReadyHandler);
  42.    _map.addControl(new NavigationControl());
  43.    _map.addControl(new MapTypeControl());
  44.  
  45.    // add to stage
  46.    addChild(_map);
  47.   }
  48.  
  49.   private function mapReadyHandler(event:MapEvent):void
  50.   {
  51.    _marker = new Marker(new LatLng(52.365983,4.80757));
  52.    _marker.addEventListener(MapMouseEvent.CLICK, onMarkerClicked);
  53.    _map.addOverlay(_marker);
  54.  
  55.    onMarkerClicked();
  56.   }
  57.  
  58.   private function mapPreInitializeHandler(event:MapEvent):void
  59.   {
  60.    _map.removeEventListener(MapEvent.MAP_PREINITIALIZE, mapPreInitializeHandler);  
  61.  
  62.    var mapOptions:MapOptions = new MapOptions();
  63.    mapOptions.center = new LatLng(52.365983,4.80757);
  64.    mapOptions.zoom = 17;
  65.    mapOptions.mapType = MapType.SATELLITE_MAP_TYPE;
  66.    _map.setInitOptions(mapOptions);
  67.   }
  68.  
  69.   private function onMarkerClicked(event:MapMouseEvent = null):void
  70.   {
  71.    _marker.openInfoWindow(new InfoWindowOptions({title: "Home sweet home", content: "Ooh no, my house isn't available!!"}));
  72.   }
  73.  }
  74. }

Comments

Comments are closed.

-->