原创:flash制作google地图查看器

安装Adobe Flash CS4 Professional 

配置google地图支持,下载google开发插件http://maps.googleapis.com/maps/flash/release/sdk.zip

在C:/Program Files/Adobe/Adobe Flash CS4/Common/Configuration/Components目录下新建一个google目录

把插件压缩包里面的map_1_18.swc复制到google目录

要在你的网站上显示地图你需要有个google地图api接口,

可以到http://code.google.com/intl/nl/apis/maps/signup.html去申请,

会让你输入你的网站然后自动生成一个Google Maps API Key文件

这个文件后面会用到

然后新建一个as 3.0

进去后默认flash的背景大小为550*400

为新建的文件命名为google_maps.fla

在库里面我们会看到先前配置的google maps插件,把它拖入到我们的舞台中央就可以了

然后打开时间轴,给时间轴的层重命名为actions,

然后点击时间轴的第一帧右键动作,输入下面代码

    import com.google.maps.LatLng;  

import com.google.maps.Map;  

import com.google.maps.Map3D;  

import com.google.maps.MapEvent;  

import com.google.maps.MapType;  

import com.google.maps.View;  

import com.google.maps.geom.Attitude;  

import com.google.maps.controls.NavigationControl;  

import com.google.maps.controls.MapTypeControl;  

import com.google.maps.controls.OverviewMapControl;  

// Variables  

var map:Map3D;  

// Call the function to create the map  

add_map();  

// Function that adds the map on stage  

function add_map()  

{  

    map = new Map3D();  

        map.key = 'abcdefg';  //你申请到的google maps key

    map.setSize(new Point(stage.stageWidth, stage.stageHeight));  

        map.addEventListener(MapEvent.MAP_READY, onMapReady);  

        this.addChild(map);  

}  

// Function that will fire once map is created  

function onMapReady(event:MapEvent):void  

{  

    map.setCenter(new LatLng(31.085485, 121.253597), 13);  //这里是你要显示的坐标

    map.viewMode = View.VIEWMODE_PERSPECTIVE;  

    map.setAttitude(new Attitude(20,40,0));  

    map.addControl(new MapTypeControl());  

        map.addControl(new OverviewMapControl());  

        map.addControl(new NavigationControl());  

}  

保存一下

然后测试flash

完成后就会看到下面的效果

可以把这个生成好的flash放到网站也可以自己重新编写一个html格式的页面

下面是单独做个html网站

<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN"   

  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  

<html xmlns="http://www.w3.org/1999/xhtml">  

  <head>  

    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>  

    <title>Google Maps JavaScript API Example</title>  

    <script src="http://ditu.google.cn/maps?file=api&v=2&key=abcdefg&sensor=true_or_false"  

            type="text/javascript"></script>  //用google maps api生成的脚本写入到网站页面

    <script type="text/javascript">  

    function initialize() {  

      if (GBrowserIsCompatible()) {  

        var map = new GMap2(document.getElementById("map_canvas"));  

        map.setCenter(new GLatLng(31.085485, 121.253597), 13);  //自己定义坐标位置

      }  

    }  

    </script>  

  </head>  

  <body onload="initialize()" onunload="GUnload()">  

    <div id="map_canvas" style="width: 500px; height: 300px"></div>  

  </body>  

</html>

 

技术交流qq:305142598

猜你喜欢

转载自blog.csdn.net/wyhwlls/article/details/5715285