1 Reply Latest reply on Nov 20, 2009 6:05 PM by harihisu

    Need help with script for Google Maps.

    kaz8teen

      I just started using Flex to create a map with markers on it. The markers are being loaded from an XML file. But they aren't loading. I'm also getting this error.


      1013: The private attribute may be used only on class property definitions.     

      Referring to...     

      private function goGeocode(event:Event):void {

      Entire code below. So, I need help loading the XML data and clearing the error. Any takers? Any help appreciated!

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:maps="com.google.maps.*" 
        width="100%" height="100%" layout="absolute" viewSourceURL="srcview/index.html">
       <mx:Panel title="Find Dragon Bleu Near You" width="100%" height="100%" color="#FF9024" borderColor="#001A35" borderStyle="none">
       <mx:VBox width="100%" height="100%" borderColor="#0B2A54">
       <mx:HBox width="100%" height="25">
        <mx:Label
           text="Enter Zip Code: "/>
        <mx:TextInput
           id="address"
           text="48917"
           dropShadowColor="0x000000"
            enter="goGeocode(event);"
        />
        <mx:Button
           id="submitButton" label="Search"
            click="goGeocode(event);"
        />
       </mx:HBox>
        <maps:Map 
          id="map" 
          key="ABQIAAAATqDu4uAIAryq9wgO8QvROhS1Ty5pbIhgzWgsWrQip6N6Hz6-fBRQ_NtWP9sHgo1hTLZM4Gsf2mPVmA" 
          mapevent_mapready="onMapReady(event)"
          width="100%" height="100%"/>
       </mx:VBox>
       </mx:Panel>
       <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.controls.ZoomControl;
      import com.google.maps.controls.PositionControl;
      import com.google.maps.controls.MapTypeControl;
      import com.google.maps.overlays.MarkerOptions;  
      import com.google.maps.overlays.Marker; 
      import com.google.maps.InfoWindowOptions;
      import com.google.maps.MapMouseEvent;
      import com.google.maps.services.ClientGeocoder;
      import com.google.maps.services.GeocodingEvent;
      import com.google.maps.services.ClientGeocoderOptions;
      import mx.controls.Alert;
      import flash.net.URLLoader;
      import flash.net.URLRequest;
      import flash.display.*;
      import flash.events.*;
      import flash.net.*;  
      import flash.events.EventDispatcher;
      
          private function onMapReady(event:Event):void {
              map.enableScrollWheelZoom();
              map.enableContinuousZoom();
              map.addControl(new ZoomControl());
              map.addControl(new PositionControl());
              map.addControl(new MapTypeControl());
              map.setCenter(new LatLng(42.25796,-83.209568), 8, MapType.NORMAL_MAP_TYPE);  
                xmlLoader();
             }
      
           private function xmlLoader() :void {       
           function loadXML(e:Event):void{  
           XML.ignoreWhitespace = true;   
           var map_xml:XML = new XML(e.target.data);  
           var xmlLoader:URLLoader = new URLLoader();  
           xmlLoader.addEventListener(Event.COMPLETE, loadXML);  
           xmlLoader.load(new URLRequest("http://dragonbleuusa.com/locations.xml"));
      
           for (var i:Number = 0; i < map_xml.location.length(); i++){  
           var latlng:LatLng = new LatLng(map_xml.location[i].lat, map_xml.location[i].lon);
           var tip:Object = map_xml.location[i].name_tip;
           var myTitle:String = map_xml.location[i].title_tip;
           var myContent:String = map_xml.location[i].content_tip;     
           
           map.addOverlay(createMarker(latlng,i, tip, myTitle, myContent));
            }
       
           function createMarker(latlng:LatLng, number:Number, tip:Object, myTitle:Object, myContent:Object):Marker {
           var i:Marker = new Marker(
           latlng,
           new MarkerOptions({ hasShadow: true, tooltip: ""+tip  
          })
                      );
          return i;
           }
      
           private function goGeocode(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);
                }
              });
              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:Application>
      
        • 1. Re: Need help with script for Google Maps.
          harihisu

          Problem begins on these lines of code

           

          private function xmlLoader() :void {       
               function loadXML(e:Event):void{ 

           

          From the 1st line above on, all functions below are nested into xmlLoader. Thus, they are NOT class property and cannot be added "private" attribute.

          You should seperate functions as much as possible to clarify the code and ease the debugging process.