3

I've been trying to set <div id="myMarker"> or <div class="myClass">attributes of google map markers so that I can later apply CSS formatting to them.

I understand that google.maps.Marker class are extension of the MVCObject so I use for example:

var marker = new google.maps.Marker(markerOptions);
marker.set('id', 'myMarker');
console.log(marker.get('id');

Everything is good the property id is set as shown in console log. In fact, I don't even have to use .set() I can write it directly in markerOptions. Anyways, when I do a div inspection I see that the property I set, in this case id="myMarker" , does not appear in the marker markup as I intended. In other words, indeed marker has a property key named id whose value is myMarker but it is not the <div id="myMarker"> that I intent to produce for later css formatting.

I have seen that every marker belongs to a element that is usually referenced by the title attribute. I am wondering if there is a more straightforward way to do that (such as a class or an Id).

So I'm stuck in figuring this out since a similar question in SO indicates .set(key,value) works. Indeed it works for setting a property but this property however is not inserted as html markup for later referencing and formatting. Any lights shed would be most helpful. Regards.

geocodezip
  • 158,664
  • 13
  • 220
  • 245
edunuke
  • 160
  • 2
  • 7
  • There aren't any documented methods to do that. If you want to add access to the id & class of a "marker" on your map, you need to create a custom marker using a [Custom Overlay](https://developers.google.com/maps/documentation/javascript/customoverlays). Possibly relevant question: [Replace Markers by html content](http://stackoverflow.com/questions/8918995/replace-markers-by-html-content) – geocodezip Sep 03 '14 at 19:16
  • So the most straight forward way is for example to load the markers as geojson layer with a property called `"id":"myMaker"` and then find the corresponding marker by checking the geojson data? Thank you for the reply @geocodezip – edunuke Sep 03 '14 at 19:23

0 Answers0