Dynamic Google Maps API InfoWindow HTML Content

Posted by Peter Hanneman on Stack Overflow See other posts from Stack Overflow or by Peter Hanneman
Published on 2010-06-15T20:42:10Z Indexed on 2010/06/15 20:42 UTC
Read the original article Hit count: 419

Filed under:
|
|
|
|

I am working in Flash Builder 4 with Google Map's ActionScript API. I have created a map, loaded some custom markers onto it and added some MouseEvent listeners to each marker.

The trouble comes when I load an InfoWindow panel. I want to dynamically set the htmlContent based off of information stored in a database. The trouble is that this information can change every couple of seconds and each marker has a unique data set so I can not statically set it at the time I actually create the markers. I have a method that will every minute or so load all of the records from my database into an Object variable. Everything I need to display in the htmlContent is contained in this object under a unique identifier.

The basic crux of the problem is that there is no way for me to uniquely identify an info window, so I can not determine what information to pull into the panel.

marker.addEventListener(MapMouseEvent.ROLL_OVER, function(e:MapMouseEvent):void { showInfoWindow(e.latLng) }, false, 0, false);

That is my mouse event listener. The function I call, "showInfowindow" looks like this:

private function showInfoWindow(latlng:LatLng):void
{
    var options:InfoWindowOptions = new InfoWindowOptions({title: appData[*I NEED A UNIQUE ID HERE!!!*].type + " Summary", contentHTML: appData[*I NEED A UNIQUE ID HERE!!!*].info});
    this.map.openInfoWindow(latlng, options);
}

I thought I was onto something by being able to pass a variable in my event listener declaration, but it simply hates having a dynamic variable passed through, it only returns the last value use.

Example:

marker.addEventListener(MapMouseEvent.ROLL_OVER, function(e:MapMouseEvent):void { showInfoWindow(e.latLng, record.unit_id) }, false, 0, false);

That solution is painfully close to working. I iterate through a loop to create my markers when I try the above solution and roll over a marker I get information, but every marker's information reflects whatever information the last marker created had.

I apologize for the long explaination but I just wanted to make my question as clear as possible. Does anyone have any ideas about how to patch up my almost-there-solution that I posted at the bottom or any from the ground up solutions?

Thanks in advance,

Peter Hanneman

© Stack Overflow or respective owner

Related posts about flex

Related posts about dynamic