Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom tooltip for google map marker ?

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 ?

like image 932
Oleg Dats Avatar asked Mar 06 '12 09:03

Oleg Dats


People also ask

How do I add a tooltip to Google Maps?

You can either use "title" and "url", or infowindow with href embedded, to provide tooltips and hyperlinks for map markers.

How do you customize a marker in maps?

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.

How do I put InfoWindow on marker?

Move an info windowAttach the info window to a new marker using the InfoWindow. open() method. Note: If you call open() without passing a marker, the InfoWindow will use the position specified upon construction through the InfoWindowOptions object literal.


2 Answers

Here is what I did on a project if you want a DIY solution.

  1. Create a hidden div on your page with css position set to absolute. Make sure your DIV appears on top of your map container (z-index).
  2. Bind mouseover and mouseout events to your markers to trigger a showDiv / hideDiv function.
  3. When mouse hovers a marker, get the mouse x,y position, set the DIV top and left css values accordingly and set its css to display:block;
  4. When mouse is out, hide the DIV again.

This way you can really control how your "infowindow" appears and what it will contain. Good luck.

like image 100
MrUpsidown Avatar answered Sep 24 '22 21:09

MrUpsidown


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.

like image 29
Oliver Avatar answered Sep 23 '22 21:09

Oliver