Hi,

I'm having problems incorporating a search by address funciton into my
map. The example I'm following is this:

http://gmaps-samples-flash.googlecode.com/svn/trunk/samplecode/GeocodingSimple.mxml

The problem I have is that I have a MapController I call in my init
function. Here's my mxml code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application scriptTimeLimit="360"
xmlns:mx="http://www.adobe.com/2006/mxml"; horizontalAlign="center"
xmlns="*" layout="absolute" width="100%" height="100%"
xmlns:maps="com.google.maps.*" backgroundColor="#FFFFFF">


<mx:Script>
        <![CDATA[
                import mx.events.FlexEvent;
                import mx.controls.Button;
                import ca.pentura.controller.MapController;
                import com.google.maps.*;
                import ca.pentura.controller.events.TraceEvent;
                
                 import mx.controls.Alert;
            import mx.events.ResizeEvent;

            import com.google.maps.interfaces.IMapType;
            import com.google.maps.InfoWindowOptions;
            import com.google.maps.overlays.Marker;
            import com.google.maps.services.Placemark;
            import com.google.maps.services.GeocodingEvent;
            import com.google.maps.services.ClientGeocoder;
            import com.google.maps.controls.ZoomControl;
            import com.google.maps.MapType;
            import com.google.maps.MapZoomEvent;
            import com.google.maps.MapMouseEvent;
            import com.google.maps.LatLng;
            import com.google.maps.MapEvent;
            import com.google.maps.Map;

            private var map:Map;
            private var geocoder:ClientGeocoder;
            //public var geocoder:ClientGeocoder;
            private var contentFormat:TextFormat;
            private var mapTypes:Array;
            private var currentMapType:Number;

            [Bindable] private var currentMapZoom:Number;

                
                private var controller:MapController;
                
        
                
                private function init(thisMap:Map):void
                {
                        try
                        {
                                //         geoCoder(null);
              //  intMapType();

                                controller = new MapController(thisMap);
                                // add for search:
                        //       map.addEventListener(MapEvent.MAP_READY, 
mapReadyHandler);
              //
map.addEventListener(MapZoomEvent.ZOOM_RANGE_CHANGED, updateMapZoom);

             //   mapComponent.addChild(map);


                        }
                        catch(error:Error)
                        {
                                trace('INIT ERR: ' + error.toString());
                        }
                }
                
                                
                
                 private function mapReadyHandler(event:MapEvent):void
            {
                currentMapZoom = 11;

     //           geoCoder(null);
      //          intMapType();
      //         intMapZoom();
            }

            // following is for second search by address example
             private function onMapReady(event:Event):void {
                
                /*
                        map.enableScrollWheelZoom();
                        map.enableContinuousZoom();
                       */
                
                
                        // moved from init
                        //controller = new MapController(thisMap);
                      //  controller = new MapController(this.map);
                       }





            private function doGeocode(event:Event):void {
                        // Geocoding example
                        var geocoder:ClientGeocoder = new ClientGeocoder();
                
                        geocoder.addEventListener(
                          GeocodingEvent.GEOCODING_SUCCESS,
                          function(event:GeocodingEvent):void {
                          var placemarks:Array = event.response.placemarks;
                          if (placemarks.length > 0) {
                            map.setCenter(placemarks[0].point);
                            var marker:Marker = new Marker(placemarks[0].point);
                
                            marker.addEventListener(MapMouseEvent.CLICK, 
function
(event:MapMouseEvent):void {
                                marker.openInfoWindow(new
InfoWindowOptions({content: placemarks[0].address}));
                            });
                             //map.addOverlay(marker);
                            mapContainer.addOverlay(marker);
                          }
                        });
                        geocoder.addEventListener(
                          GeocodingEvent.GEOCODING_FAILURE,
                          function(event:GeocodingEvent):void {
                            Alert.show("Geocoding failed");
                            trace(event);
                            trace(event.status);
                          });
                       geocoder.geocode(address.text);
                      }         
                
        ]]>
</mx:Script>

<mx:Canvas width="100%" height="100%" backgroundColor="#FFFFFF" >
        <maps:Map id="mapContainer" initialize="init(this.mapContainer);"
width="100%" height="100%" horizontalCenter="0" verticalCenter="0">
        </maps:Map>
        
        <!--<maps:Map
    id="map"
    key="MY API KEY"
    mapevent_mapready="onMapReady(event)"
    width="100%" height="100%"/>-->
        
</mx:Canvas>

<mx:UIComponent id="mapComponent" width="100%" height="100%"  />

        <mx:ApplicationControlBar width="40%" cornerRadius="0"
fillColors="[0xFFFFFF, 0xFFFFFF]" fillAlphas="[1,1]" y="605">

            <mx:Label text="Address:" />
            <mx:TextInput id="address" width="150" text="115 wolseley
st, toronto" toolTip="Address Text Input"  enter="doGeocode(event);"
/>


            <mx:Button label="find" click="doGeocode(event);" />

            <mx:Spacer width="100%" />


        </mx:ApplicationControlBar>



</mx:Application>

And here's the relevant code from the MapController that is called in
the above init function:

public function MapController(map:Map)
                {       
                        newMap = map;
                        
                        //this.mapMode = MapMode.EXPERIENCE_MODE;
                        this.mapMode = MapMode.FIND_MODE;

                                
                        newMap.key = "MY API KEY";      
                        newMap.addEventListener(MapEvent.MAP_READY, 
mapReadyHandler);
                        
                        newMap.addEventListener(MapMoveEvent.MOVE_END, 
getNewBounds);
                        this.newMap.addEventListener(MapMoveEvent.MOVE_END, 
setCurrentBounds);
                        
                        //set maximum explorable bounds
                        mapBounds = new LatLngBounds(new LatLng(-80, -165), new 
LatLng(80,165));                                

 etc.

All the pieces seem to be in place but I'm having trouble doing it.
Note I can get the address search to work by itself by commenting out
the <maps:Map
    id="map"
    key="MY API KEY"
    mapevent_mapready="onMapReady(event)"
    width="100%" height="100%"/> in the mxml file and commenting out
the other 'maps' part that works with MapController.

Thanks for any help on this.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API For Flash" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-maps-api-for-flash?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to