开发者

Refresh/Reload Google map

I have a Google map and I want to refresh or reload 开发者_JS百科map from my code. How is it possible?

I go through this link http://www.codigoactionscript.org/langref/googlemaps/com/google/maps/MapEvent.html but there is nothing for refresh/reload map there.


This isn't exactly "refreshing the map"; however, accomplishes the same thing.

Use a timer to remove the map from the stage and add it again, calling the full Google map lifecycle:


package
{
    import com.google.maps.LatLng;
    import com.google.maps.Map;
    import com.google.maps.MapEvent;
    import com.google.maps.MapType;

    import flash.display.Sprite;
    import flash.events.TimerEvent;
    import flash.geom.Point;
    import flash.utils.Timer;

    public class Test extends Sprite
    {

        private var _map:Map;

        private var _timer:Timer;

        public function Test()
        {
            super();

            createMap();

            _timer = new Timer(300000); // 5-min
            _timer.addEventListener(TimerEvent.TIMER, timerHandler);
            _timer.start();
        }

        private function timerHandler(event:TimerEvent):void
        {
            while (numChildren > 0)
                removeChildAt(0);

            createMap();
        }

        protected function createMap():void
        {
            _map = new Map();
            _map.key = "YOUR_API_KEY";
            _map.sensor = "false";
            _map.setSize(new Point(stage.stageWidth, stage.stageHeight));
            addChild(_map);

            _map.addEventListener(MapEvent.MAP_READY, mapReadyHandler);
        }

        protected function mapReadyHandler(event:MapEvent):void
        {
            _map.removeEventListener(MapEvent.MAP_READY, mapReadyHandler);
            _map.setCenter(new LatLng(37.4419, -122.1419), 13, MapType.NORMAL_MAP_TYPE);
        }

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜