Unknown developer
Unknown developer

Reputation: 5970

Apply Jquery to google maps marker

I am using a custom marker for google maps:

 var myLatlng = new google.maps.LatLng(33.0309,13.723497); 
 var image = "img/svoura.png";
 var marker = new google.maps.Marker({    
  position: myLatlng,   
  draggable: true,     
  map: map, 
  icon:image   
  });  

I want to apply some jquery function (e.g. rotation) to the icon marker. Obviously, I need an ID for it. In what way may I assign an ID? Thank you

Upvotes: 1

Views: 1633

Answers (1)

Adam Jenkins
Adam Jenkins

Reputation: 55792

Not as easy as you might've hoped. There's no way to get the DOM element that represents a marker, in part because the newest google maps API doesn't even use a DOM element - it uses a canvas element (in supported browsers) to draw the markers on the tiles.

Alternatively, you could create your own marker using a custom overlay and then you'd have access to the DOM element and be able to manipulate it directly with JavaScript, but this is not an exercise for somebody who hasn't/is not willing to delve pretty deep into the inner workings of the Google Maps API, just to let you know.

Upvotes: 1

Related Questions