TwelvestoneFlash

Google Maps API in 30 seconds


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
persist
 
2009-05-14

Need to throw a customized clickable map marker on a map in your app and don't have time to dive through the docs?

Do this:

Make a movieclip display object and set to export in your library. Call it MapNode.

Then add this code.

import com.google.maps.MapEvent; import com.google.maps.MapMouseEvent; import com.google.maps.Map; import com.google.maps.overlays.Marker; import com.google.maps.overlays.MarkerOptions; import com.google.maps.InfoWindowOptions; import com.google.maps.MapType; import com.google.maps.LatLng;

var key = "YOUR KEY"

var applicationContainer = this;

var map:Map = new Map(); map.key = key; map.setSize(new Point(stage.stageWidth, stage.stageHeight)); map.addEventListener(MapEvent.MAP_READY, onMapReady); this.addChild(map);

function onMapReady(event:Event):void {

    map.setCenter(new LatLng(40.736072,-73.992062), 1.45,          
    MapType.PHYSICAL_MAP_TYPE);

            //If you want to put something ABOVE the map, the time to do it is here. But don't cover their logo or ToS link, as it's against the ToS.
            //var overlayClip = new overlay();
    //overlayClip.alpha = 0.7;
            //applicationContainer.addChild(overlayClip);
    addMarker();

}

function addMarker(){

    var markerOptions:MarkerOptions = new MarkerOptions();
            markerOptions.icon = new MapNode();
    markerOptions.icon.addEventListener(MouseEvent.MOUSE_OVER, nodeOver);
    markerOptions.icon.addEventListener(MouseEvent.MOUSE_OUT, nodeOut);
            markerOptions.iconAlignment = MarkerOptions.ALIGN_HORIZONTAL_CENTER;
            markerOptions.iconOffset = new Point(1, 1);
    markerOptions.hasShadow = true;     
    var latlng:LatLng = new LatLng(45, 45);
    var marker:Marker = new Marker(latlng, markerOptions);
    map.addOverlay(marker);

}

function nodeOver(e:MouseEvent){ var me = e.target; me.gotoAndStop(2); } function nodeOut(e:MouseEvent){ var me = e.target; me.gotoAndStop(1); }

You need to put in your own key. You can make MapNode a class and get rid of my example mouse events.

That's it. Easy as pie. Why they don't have an example for "I just want to make a custom map marker" is beyond me. The docs imply the display object in icon can only be an image, but they really mean DisplayObject.

Hope this saves someone time someday.

BOBBYLOVEVILLE
 
2009-05-14

schweet, thanks persist

oh and, hi! k

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

Google Maps API in 30 seconds