Loading XML Data to Dynamic Text Field inside MC in Google Maps API

Hello.

First of all, I must say, I’m just starting with Flash and AS, so please, be patient :slight_smile:

I have a simple Google Maps API with external data loaded from XML file (location, lat, long, info etc.). I also have a custom marker as a MovieClip (marker_mc), which works fine, but I want to add a Dynamic Text Field (label_txt) to this MovieClip and load a simple data (<label>) to it from same XML file (distribubtion.xml), so as a result every location would have it’s own label on the marker.

I know how flash loads XML data, but what I don’t know is how to include that in Google Maps API (if it’s even possible).

Here’s the code:

// Import
import com.google.maps.LatLng;
import com.google.maps.LatLngBounds;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.View;
import com.google.maps.geom.Attitude;
import com.google.maps.controls.NavigationControl;
import com.google.maps.controls.MapTypeControl;
import com.google.maps.controls.OverviewMapControl;
import com.google.maps.overlays.*;
import com.google.maps.InfoWindowOptions;
import com.google.maps.MapMouseEvent;
import flash.geom.Point;
import flash.events.Event;

// Variables  
var map:Map;

// Call the function to create the map  
add_map();

// Function that adds the map on stage  
function add_map()
{
    map = new Map();
    map.key = 'ABQIAAAAtX9VFxZ8XslOuYUe0XqN_BRJWeqb0pLnbJLIJ72AUaJFRZBBtxSZTjWc-oyYV0_gpTSM66q-Sv7SBw';
    map.sensor = "true";
    map.setSize(new Point(900,552));
    map.addEventListener(MapEvent.MAP_READY, onMapReady);
    this.addChild(map);
}

// Function that will fire once map is created  
function onMapReady(event:MapEvent):void
{
    map.setCenter(new LatLng(54.20101,-1.911621), 6);

    map.addControl(new MapTypeControl());
    map.addControl(new OverviewMapControl());
    map.addControl(new NavigationControl());
    
    // Load the xml  
    load_xml();
}

// Add Markers On The Map  
function createMarker(latlng:LatLng, number:Number, tip, myTitle, myContent):Marker
{
    // create Custom marker object  
    var markerPin:marker_mc = new marker_mc();
    
    // Marker Pin scaling
    //markerPin.width = 20;
    //markerPin.height = 42;

    var i:Marker = new Marker(  
                                   latlng,  
                                   new MarkerOptions({  
                                                         hasShadow: true,  
                                                         icon: this.addChild(markerPin),  
                                                         tooltip: ""+tip  
                                                        
                                                    })  
                                  );
    i.addEventListener(MapMouseEvent.CLICK, function(event:MapMouseEvent):void  
         {  
             map.openInfoWindow(event.latLng, new InfoWindowOptions({  
                                                                        titleHTML: ""+myTitle,  
                                                                        contentHTML: ""+myContent  
                                                                   }));  
       
         });
    return i;
}

// Function that will load the xml  
function loadXML(e:Event):void
{
    XML.ignoreWhitespace = true;
    var map_xml:XML = new XML(e.target.data);
    for (var i:Number = 0; i < map_xml.location.length(); i++)
    {
        var latlng:LatLng = new LatLng(map_xml.location*.lat,map_xml.location*.lon);
        var tip = map_xml.location*.name_tip;
        var myTitle:String = map_xml.location*.title_tip;
        var myContent:String = map_xml.location*.content_tip;
        
        map.addOverlay(createMarker(latlng, i, tip, myTitle, myContent));
    }
}

function load_xml()
{
    var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.addEventListener(Event.COMPLETE, loadXML);
    xmlLoader.load(new URLRequest("distribution.xml"));
}

and XML structure:

<map_xml>
<!--   LOCATION LOCATION LOCATION   -->

<!--   Location 1   -->
  <location>
   <lat></lat>
   <lon></lon>
   <name_tip></name_tip>
   <title_tip><![CDATA[]></title_tip>
   <content_tip><![CDATA[]]></content_tip>
   <label></label>
  </location>

</map_xml>

Any help will be much appreciated.
Thanks in advance.
rtn87