forked from: 住所から座標を求めるテスト(3)

by tsu_droid
コードを自分なりに見易く編集
♥2 | Line 109 | Modified 2012-01-04 00:13:03 | MIT License
play

ActionScript3 source code

/**
 * Copyright tsu_droid ( http://wonderfl.net/user/tsu_droid )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/t15Yf
 */

<?xml version="1.0" encoding="utf-8"?>
<!-- forked from unagi_ningen's 住所から座標を求めるテスト(3) -->
<!-- forked from unagi_ningen's 住所から座標を求めるテスト(2) -->
<!-- forked from unagi_ningen's 住所から座標を求めるテスト。 -->

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" viewSourceURL="srcview/index.html">
 <maps:Map3D xmlns:maps="com.google.maps.*" 
        mapevent_mappreinitialize="onMapPreinitialize(event)"
        mapevent_mapready="onMapReady(event)"
        id="map" 
        key="ABQIAAAA7QUChpcnvnmXxsjC7s1fCxQGj0PqsCtxKvarsoS-iqLdqZSKfxTd7Xf-2rEc_PC9o8IsJde80Wnj4g" 
        width="100%" height="100%"/>
<mx:Script>
<![CDATA[

    // 東京スカイツリー 東京都墨田区押上1丁目1−13
    // 大阪市役所 大阪府大阪市北区中之島1丁目3−20

    import com.google.maps.*;
    import com.google.maps.services.*;

    import flash.display.*;
    import flash.text.TextField;
    import flash.events.*;
    import flash.text.*;
     
    private var  inputTf:TextField;
    private var  myStr:String;
    
    public var latlng:LatLng; // 外部参照用

    private function onMapPreinitialize(evt:MapEvent):void {
            var myMapOptions:MapOptions = new MapOptions;
            myMapOptions.zoom = 12;
            myMapOptions.center = new LatLng(35.6894875, 139.6917064);// 初期位置(都庁になる筈だが・・・)
            myMapOptions.mapType = MapType.NORMAL_MAP_TYPE;
            myMapOptions.viewMode = View.VIEWMODE_ORTHOGONAL;
            myMapOptions.attitude = new Attitude(20, 30, 0);
            map.setInitOptions(myMapOptions);

            addMarkers();

            inputTf = new TextField();
            inputTf.border = true;
            inputTf.x = 259;
            inputTf.y = 240;
            inputTf.width = 200;
            inputTf.height = 200;
            inputTf.text = "";
            inputTf.type = TextFieldType.INPUT;
            inputTf.multiline = true;
            parent.addChild(inputTf);

            var btnText:TextField = new TextField();
            btnText.x = this.stage.stageWidth - 50;
            btnText.y = this.stage.stageHeight - 44;
            btnText.width = 45;
            btnText.height = 21;
            btnText.text = "検索";
            btnText.selectable = false;
            parent.addChild(btnText);

            var button:Sprite = new Sprite();
            button.graphics.lineStyle(2, 0x999999, 1.0);
            button.graphics.beginFill(0xCCCCCC, 0);
            button.graphics.drawRoundRect(stage.stageWidth-60, stage.stageHeight-44, 55, 20, 10, 10);
            button.buttonMode = true;
            button.addEventListener(MouseEvent.CLICK, txtInputFunc);
            parent.addChild(button);

            /*
            var position:LatLng = new LatLng(40.756, -73.987);
            var marker:Marker = new Marker(position);
            map.addOverlay(marker);
            */
     }

    private function movMap(pot:LatLng):void {
            if (pot) {
                map.setCenter(pot);
                var marker:Marker = new Marker(pot);
                map.addOverlay(marker);
            }
    }

    private function onSearch(str0:String):void {
            var geocoder:ClientGeocoder = new ClientGeocoder();
            myStr = str0;
            geocoder.addEventListener(GeocodingEvent.GEOCODING_SUCCESS, onGeocodeSuccess);
            geocoder.geocode(str0);
     }

    private function addMarkers():void {
    }

        private function txtInputFunc(evt:Event):void {
            //tf.appendText("テキスト文字数:"+inputTf.length+"\n");
            var str:String = inputTf.text;
            var sp:Array = str.split("\r");
            for (var idx:Number = 0; idx<sp.length; idx++) {
                //tf.text = tf.text+i+")"+sp[idx]+"\n";
                onSearch(sp[idx]);
            }
            //tf.text = "テキスト文字数:"+sp.length+"\n"+"\n";
        }

    private function onGeocodeSuccess(evt:GeocodingEvent):void {
            if (evt.response.placemarks.length == 0) {
                return;
            }
            
            latlng = evt.response.placemarks[0].point;
            map.setCenter(latlng);
            parent.inputTf.appendText(latlng);
            
            var marker:Marker = new Marker(latlng);
            
            var marker:Marker = 
            new Marker(
                latlng, 
                new MarkerOptions(
                    {
                        strokeStyle:new StrokeStyle({color:0x987654}), 
                        fillStyle:new FillStyle({color:0xFFFFFF, alpha:0.9}), 
                        radius:10,
                        hasShadow:true, 
                        
                        label:evt.response.name, 
                        //labelFormat:new TextFormat(null, null, 0x4465d7)
                        labelFormat:new TextFormat(null, null, 0x000000)
                    }
                )
            
            );

            map.addOverlay(marker);
            
            //map.openInfoWindow(latlng, new InfoWindowOptions({content:myStr}));
            //map.openInfoWindowHtml(latlng, "wahaha", offset);

     }

    private function onMapReady(evt:MapEvent):void {
            map.addControl(new NavigationControl());
    }
        
]]>
</mx:Script>
</mx:Application>