Forums: Flash:

 

Google Maps API in 30 seconds

first
 

persist Google Maps API in 30 seconds

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

schweet, thanks persist

oh and, hi! Wavey

 
first
 

Forums: Flash: Google Maps API in 30 seconds

 
New Post
 
You must be logged in to post