google map APIつかってみた

google map APIキー取得

ここAPIを登録する。
rascutlocalhostにアクセスしてデータを取得してきたいので
URLを http://localhost で取得した。

rascutで起動

基本ここの通りのことをしてみた。
ここではmxmlcでのコンパイルの仕方しか書いてなかったので
rascutでの起動の仕方を書いておく。

  • MapSimple.mxml(引用)
<?xml version="1.0" encoding="utf-8"?>
    <!-- Copyright 2007 Google Inc. -->
    <!-- All Rights Reserved. -->
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%">
    <mx:Panel title="Google Maps API for Flash - Simple Map" width="100%" height="100%">
    <mx:UIComponent id="mapContainer"
    initialize="startMap(event);"
    resize="resizeMap(event)"
    width="100%" height="100%"/>
    </mx:Panel>
    <mx:Script>
    <![CDATA[
    import flash.events.Event;
    import com.google.maps.MapEvent;
    import com.google.maps.Map;
    import com.google.maps.MapType;
    import com.google.maps.LatLng;

    private var map:Map;

    public function startMap(event:Event):void {
        map = new Map();
        map.key = "上で取得したキー";          //ここだけ追記
        map.addEventListener(MapEvent.MAP_READY, onMapReady);
        mapContainer.addChild(map);
    }   

    public function resizeMap(event:Event):void {
        map.setSize(new Point(mapContainer.width, mapContainer.height));
    }   

    private function onMapReady(event:Event):void {
        map.setCenter(new LatLng(40.736072,-73.992062), 14, MapType.NORMAL_MAP_TYPE);
    }   
    ]]> 
    </mx:Script>
</mx:Application>

rascut -c [mxmlcのオプションを指定] MapSimple.mxml -s
rascut -c -library-path+=lib MapSimple.mxml -s

またはflex-config.xmlファイルにかけばいい。
結構楽にためせれた。明日はもっと色々ためしてみよう。