Position custom and fancy overlay dialog on Google Maps V3

Nowadays many sites uses embedded map from Google for purposes like showing object location, drive-in way or more complex stuff. Recent Google Maps Version3 (V3) API becomes very powerful, but remained very clear and easy to use.

While developing site for real estate company I faced with necessity to display fancy, complex overlays on top of the map when user clicks on the marker.

There are some standard ways of showing so called info-windows. The problem is that it is not possible put complex formatting there or catch mouse clicks events.

To solve it I have to to dig into API internals and recent version V3 has some surprises here.

The easiest way to show custom overlay is to determine coordinates of clicked marker and position DIV over the map to right position. Sounds easy.

API V2 code, that does not work in V3

I found some code that should do the trick, but it does not work. It was designed for V2 API.

After some API digging and googling, I found out that there are no documented ways of determiniting pixel position of GoogleMap point. Thats sad.

API V3 code, marker to pixel position

Here is the semi-hacked code that actually does the trick


  • gmap - is GoogleMap object
  • marker - is GoogleMap marker object
  • point - returned object contains maker coordinates related to upper-left corner of GoogleMap area

Overlay position on GoogleMap - Example

Below you can find working example, I made overlay window simple, but since it is DIV there is no limits of pushing it.

Overlay position on GoogleMap - View Code


  1. Thx! Exactly what I needed. You have more in here with the custom markers than what I wanted, but none of the AJAX or php interactivity that I had to build in. Still, I could figure that out myself. Google ought to hire you to make a clearer explanation on their v3 docs! 😛

  2. There is an issue with CSS’s scale rule when applied to clickable marker area. If map is scaled via CSS to something other than 100%, the clickable marker shape is no longer over the marker.
    * Example *
    window.onresize = function() {
    var sx = document.body.clientWidth / window.innerWidth;
    var sy = document.body.clientHeight / window.innerHeight;
    var transform = “scale(” + (1/Math.max(sx, sy)) + “)”;
    document.body.style.transform = transform;

Leave a Reply

Your email address will not be published.