天天看點

Flex3整合GOOGLE MAPS API,實作定位具體位置

首先登陸到http://code.google.com/intl/zh-CN/apis/maps/documentation/flash/basics.html

可以查到Google Maps API(Flash 版)基本知識。

要完成以下幾個步聚:

1.下載下傳Flex SDK,

2.下載下傳map_flex_1_20.swc,這個flex library.

3.建立flex項目,并加載這個類庫。

最終效果如下圖所示:

Flex3整合GOOGLE MAPS API,實作定位具體位置

4.部署這個項目,并在位址欄中輸入一個簡單事例程式:

http://localhost:8080/FlexDemo/FlexDemo-debug/FlexDemo.html#app=f87d&9c67-selectedIndex=1

Flex3整合GOOGLE MAPS API,實作定位具體位置

5.建立一個heel.mxml檔案。這個檔案的定義如下:

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

  <maps:Map xmlns:maps="com.google.maps.*" id="map" mapevent_mapready="onMapReady(event)" width="100%" height="100%"

    key="ABQIAAAAWqNQ5Z8BP0sGSC0RImJaGhTwM0brOpm-All5BF6PoaKBxRWWERSdFif9r1-SyBbv9YQ-i0B8SnodRw"/>

<mx:Script>

    <![CDATA[

    import com.google.maps.LatLng;

    import com.google.maps.Map;

    import com.google.maps.MapEvent;

    import com.google.maps.MapType;

    import com.google.maps.InfoWindowOptions;

       import com.google.maps.overlays.Marker;

    import flash.utils.Timer;

    import flash.events.TimerEvent;

    private var myTimer:Timer;

    private function onMapReady(event:Event):void {

      this.map.setCenter(new LatLng(22.742306,113.595972), 14, MapType.NORMAL_MAP_TYPE);//22.742306,113.595972

      //http://www.playgoogle.com/googlemap/tool1.html

      map.addOverlay(new Marker(new LatLng(22.741277,113.596315))); //22.742306,113.595972

     myTimer = new Timer(1500, 1);

      //使用定時器

      myTimer.addEventListener("timer", timedFunction);

      myTimer.start();

     map.openInfoWindow(map.getCenter(), new InfoWindowOptions({title: "南沙", content: "廣州某軟體所 "}));

    }

    private function timedFunction(eventArgs:TimerEvent):void {

          map.panTo(new LatLng(22.742781,113.598289));

          trace("Timer fired " + myTimer.currentCount + " times.");

    }

    ]]>

</mx:Script>

</mx:Application>

6.最終的實作效果如下所示:

Flex3整合GOOGLE MAPS API,實作定位具體位置

繼續閱讀