Reputation: 4133
I need to show some nice tooltip with image and text on mouse hover of google maps marker.
marker.setTitle - works only with text but not with html
Does google maps api have standard solution ?
Can you please suggest lib to create tooltips and make them look nice ?
Upvotes: 11
Views: 21264
Reputation: 101
Oleg, why are you you bound to the google maps api. You can inject a custom tooltip into the DOM.
Attach event listeners for mouseover, mousemove and mouseout listeners on the map (or specific parts of the map). Each of those listeners also gives you an argument giving you the mouse coordinates.
Use a fixed/absolute style on the tooltip's css for positioning it
on mouseover, inject the tooltip at the cursor position into the DOM on mousemove, update the position (left and top) on mouseout, remove the tooltip from the DOM.
I've recently built this for google maps polygons. You can repurpose my approach for any other part of your map since almost every feature on the google map supports events.
link: https://medium.com/@asimmittal/custom-tooltips-for-google-maps-in-pure-javascript-a8004b8e9458
Upvotes: 0
Reputation: 22490
Here is what I did on a project if you want a DIY solution.
This way you can really control how your "infowindow" appears and what it will contain. Good luck.
Upvotes: 4
Reputation: 11597
You could listen for the mouseover
event on the marker, and trigger an infoWindow
to appear with that event.
Once you have the infowindow, you can put pictures and text in it in a way that is well supported by the api.
Upvotes: 3