views:

385

answers:

1

Hi all,

So I'm rewriting my first google maps app and I'm looking at how I create info windows on click of a marker and it seems very inefficent to be adding a listener for each. Previously I've used GInfoWindow and EBubble (http://econym.org.uk/gmap/ebubble.htm).

I was thinking that I could use jQuery to show a div with dynamic data if I had a hook for each marker to show the window and relevant marker info (pulled from JSON). I can see each marker has a unique id (e.g. mtgt_unnamed_2822) but I'm not sure how to predicte this.

Has anyone tried this before or know how to go about it?

Thanks Denis

A: 

I don't know jQuery, but Javascript allows you to add your own custom Properties to any Object. So you can write stuff like this:

  var marker = new GMarker(...);  
  marker.ID = "mtgt_unnamed_2822";

or

function createMarker(point,newid) {
  var marker = new GMarker(point);
  marker.ID = newid;
  ...
}

Be careful not to use "marker.id" because the API could use "id" as the obfuscated internal name for an existing property in some future release. In fact avoid Property names that start with a lower case letter.

Once you've attached the .ID Property to a marker, you can read the info from the marker.ID of any marker reference whenever you need it to make the jQuery call.

Mike Williams
Thanks Mike but I'm looking for the other way around here. I want to access the google marker id (which isn't marker.id, tried that) so that I can add a generic class for jQuery selection and assoiciate also associate the id with it's specific data. This would allow me to use a jQuery class based selector which I think would be faster than adding a listener for each mark. Am I making sense?
Denis Hoctor
I don't know jQuery, so I'm not totally following you.Would it help to create a global "associative array" of marker ids?var marker = new GMarker(point);idarray(newid) = marker;Then idarray("mtgt_unnamed_2822") would be a reference to the marker which has that ID.I know that in Javascript they're not really "associative arrays" but they can be used exactly like the real associative arrays that I know and love from other languages, so that's how I like to think of them.
Mike Williams