(using flash) I have a Sprite 开发者_高级运维object that I want to show on google map. So I made a GroundOverlay object using my Sprite object, but it doesn't show up. I guess it's because Sprite is higher class than DisplayObject. (GroundOverlay seems getting DisplayObject only..?) Is there any way to us Sprite for my GroundOverlay? or alternative idea?
I get this code from this website, I don't remember the exact link but you can try, it almost what you want to do...
package
{ import flash.display.; import flash.geom.; import com.google.maps.*;
public class sample extends Sprite
{
private var polyLayer:Sprite = new Sprite();
private var mapLayer:Sprite = new Sprite();
private var map:Map = new Map();
private var center:LatLng = new LatLng(36.469889,-93.949641);
private var state:String = "39.108751,-94.586848 35.160337,-90.049495 35.474091,-97.520198";
public function sample()
{
addChild(mapLayer);
addChild(polyLayer);
map.key = "*** HERE YOUR API KEY ***";
map.sensor = 'false';
map.setSize(new Point(800, 600));
map.addEventListener(MapEvent.MAP_READY, function(event:MapEvent) {
map.enableScrollWheelZoom();
map.setMapType(MapType.NORMAL_MAP_TYPE);
map.setCenter(center, 6);
redrawPolygons();
});
map.addEventListener(MapZoomEvent.ZOOM_CHANGED, function(event:MapZoomEvent) {
redrawPolygons();
});
map.addEventListener(MapMouseEvent.DRAG_STEP, function(event:MapMouseEvent) {
redrawPolygons();
});
mapLayer.addChild(map);
}
private function redrawPolygons():void
{
polyLayer.graphics.clear();
polyLayer.graphics.lineStyle(1,0x000000,0.8);
polyLayer.graphics.beginFill(0xFF0000,0.5);
var coo:Array = state.split(" ");
for (var g=0; g<coo.length; g++) {
var latlon:LatLng = LatLng.fromUrlValue(coo[g]);
if (g==0)
polyLayer.graphics.moveTo(map.fromLatLngToViewport(latlon).x, map.fromLatLngToViewport(latlon).y);
else
polyLayer.graphics.lineTo(map.fromLatLngToViewport(latlon).x, map.fromLatLngToViewport(latlon).y);
}
polyLayer.graphics.endFill();
}
}
}
精彩评论