Google Map For Flash でLivedoor天気を表示

Google Map For FlashLivedoor天気を表示してました。
http://moeten.info/flex/20080603_tenkiMap/bin-release/main.html

カスタムアイコンの作り方

//アイコンの作成
private function setMarker( latlng:LatLng , iconurl:String ):void{
    //アイコン画像読み込み
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener( Event.COMPLETE , function (e:Event):void{
        //カスタムアイコン
        var bd:BitmapData = new BitmapData( 25, 15 );
        var mat:Matrix = new Matrix( 0.5 , 0 , 0 , 0.5 );
        bd.draw(loader.content, mat);
        var bm:Bitmap = new Bitmap(bd);
        bm.filters = [dsf];
        //アイコンの作成
        var marker:Marker = new Marker( latlng  , new MarkerOptions({
                    draggable : true,
                   icon:bm,
                   iconOffse:new Point(10,10),
                   hasShadow:false
               }));
        //アイコンの設置
        map.addOverlay(marker);
    });
    loader.load( new URLRequest( "http://moeten.info/flex/20080502_twitterAir/myproxy.php?u="+iconurl ) );
}

MarkerOptionsのiconにDisplayObjectを指定すればOK。
今回はLoaderを使ってちゃんとロードしてから描画・作成してからMarkerに設定しています。
独自の画像を使うカスタムマーカーですが、Googleさんとこのチュートリアルサンプルがわかりやすいです。

お天気アイコンはcrossdomainになるのでphpでプロキシさせてあげます。

"http://moeten.info/flex/20080502_twitterAir/myproxy.php?u="+iconurl

proxy.php

<?php
if( $_GET['u'] != "" ){
    $u = urldecode( $_GET['u'] );
    echo file_get_contents( $u );
}
?>

毎回リクエストを出すのもアレなので、キャッシュ付きproxy.php

<?php
if( $_GET['u'] != "" ){
    //URLゲット
    $u = urldecode( $_GET['u'] );
    //ファイル名作成
    $fname = "./cache/" . md5( $u );
    //すでにキャッシュある?
    if( file_exists( $fname ) ){
        //あるのでファイルから出力
        echo file_get_contents( $fname );
    }else{
        //ないのでURLからファイルをゲット
        $file =  file_get_contents( $u );
        //保存
        file_put_contents( $fname , $file );
        //出力
        echo $file;
    }
    exit;
}
?>

Livedoorさんの天気情報ですが、こちらはphpを使って事前にデータベースなどに保存しておくと便利です。
一度に全都道府県を取得するとあちらのサーバーに負荷がかかるので、cron(定期的実行)とphpのsleep(プログラムを一時停止させる)などを使うとよいと思います。
天気を取ってくるphpなソースはちょいと古い(1年くらい前)ので、修正したら載せたいと思います。
こんな感じにxmlを作成します。
http://moeten.info/maidcafe/?m=flex_tenki
お土産として、都道府県のGPSデータを置いておきます。データーベースに入れておくと便利でっす。

"1","北海道","43.06197","141.35046","1"
"2","青森県","40.82178","140.74365","2"
"3","岩手県","39.70096","141.15547","2"
"4","宮城県","38.26594","140.87549","2"
"5","秋田県","39.71539","140.10626","2"
"6","山形県","38.23758","140.36452","2"
"7","福島県","37.74733","140.47157","2"
"8","茨城県","36.33791","140.45047","3"
"9","栃木県","36.56247","139.88808","3"
"10","群馬県","36.38779","139.0638","3"
"11","埼玉県","35.85339","139.65387","3"
"12","千葉県","35.60131","140.12637","3"
"13","東京都","35.68627","139.69487","3"
"14","神奈川県","35.44445","139.64578","3"
"15","新潟県","37.89942","139.0264","4"
"16","富山県","36.69237","137.21463","4"
"17","石川県","36.59171","136.62853","4"
"18","福井県","36.06207","136.22368","4"
"19","山梨県","35.66302","138.57152","4"
"20","長野県","36.64779","138.18398","4"
"21","岐阜県","35.38808","136.72688","4"
"22","静岡県","34.97353","138.38623","4"
"23","愛知県","35.17691","136.90973","4"
"24","三重県","34.72813","136.50998","5"
"25","滋賀県","35.00097","135.87238","5"
"26","京都府","35.01952","135.75912","5"
"27","大阪府","34.68347","135.52233","5"
"28","兵庫県","34.6878","135.18575","5"
"29","奈良県","34.68179","135.83568","5"
"30","和歌山県","34.22156","135.17085","5"
"31","鳥取県","35.50033","134.24098","6"
"32","島根県","35.46919","133.05305","6"
"33","岡山県","34.65815","133.93787","6"
"34","広島県","34.39309","132.46188","6"
"35","山口県","34.18109","131.47495","6"
"36","徳島県","34.06277","134.56094","7"
"37","香川県","34.33718","134.04599","7"
"38","愛媛県","33.83861","132.76865","7"
"39","高知県","33.55756","133.53433","7"
"40","福岡県","33.60078","130.41806","8"
"41","佐賀県","33.24616","130.30139","8"
"42","長崎県","32.74123","129.87575","8"
"43","熊本県","32.78617","130.7438","8"
"44","大分県","33.23479","131.61493","8"
"45","宮崎県","31.90745","131.42601","8"
"46","鹿児島県","31.5575","130.56","8"
"47","沖縄県","26.20836","127.68269","8"