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

**URL:** <https://forum.kirupa.com/t/loading-xml-data-to-dynamic-text-field-inside-mc-in-google-maps-api/324551>\
**Category:** flash\
**Created:** [August 26, 2011, 2:02pm UTC](https://forum.kirupa.com/t/loading-xml-data-to-dynamic-text-field-inside-mc-in-google-maps-api/324551 "2011-08-26T14:02:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rtn87](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@rtn87](https://forum.kirupa.com/u/rtn87)\
**Post date:** [August 26, 2011, 2:02pm UTC](https://forum.kirupa.com/t/loading-xml-data-to-dynamic-text-field-inside-mc-in-google-maps-api/324551/1 "2011-08-26T14:02:15Z")

</div>

Hello.

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

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:

```auto
// 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:

```auto
<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
