Add HTML / ID class to Google Maps Marker (API V3)

How do I add a class or ID to the V3 API Token for Google Maps? I want to have access to markers using jQuery.

EDIT: Hello, clarkf, thanks for the answer. Using Firebug I cannot see these classes when checking my map, but I noticed that there are two divs. One for the icon and one for the button.

What I'm trying to do is: I have a list of lost pets displayed on the site, they also appear on the map. Each pet in the list has a unique identifier, and I want this certificate to be displayed on the map using the class, since the identifier must be unique, and there can be several points per pet. Therefore, I am looking for a way to add a class to a map marker. Thus, when the user selects a lost pet from the list, he selects it on the map or vice versa.

thank

Ric

+3
source share
2 answers

. , . , , . , , . , , , . , : http://www.isabellevetslostpets.com/page/search-for-a-lost-pet

( , !). ( JSON, AJAX - Firebug, ) , .

0

, , , gmnoprint ( G oogle M aps ). , , Chrome Inspector :

> var list = document.getElementsByClassName('gmnoprint');
  [...] //length=37
> for ( var i = 0, item; item = list[i]; i++ ) { console.log(item.id); }
  //(11 items with no id)
  mtgt_A.1001
  mtgt_B.1001
  mtgt_C.1001
  mtgt_D.1001
  mtgt_E.1001
  mtgt_F.1001
  mtgt_G.1001
  mtgt_H.1001
  mtgt_I.1001
  mtgt_J.1001
  mtgt_A.1000
  map_overview
  //Irrelevant information...

mtgt_[LETTER].1001. , , (mtgt_A.1000 - , - . . , , jQuery $('#mtgt_[LETTER].1001') - , , , , , ,

function getMarker(letter) {
    return $('mtgt_'+letter+'.1000');
}

ad-hoc-y, , .

0

Source: https://habr.com/ru/post/1771118/


All Articles