4

I'm currently working on a project that requires that I have a div stacked above a Google Map. However, I need to pass the mousemove event of the div to the Map. To do that, I need to find the LatLng co-ordinates from the map container pixel co-ordinate (since triggering the Maps mousemove event requires the LatLng co-ordinates).

Is there any other way to pass the mousemove event from the div to the map, and if not, how do I go from the Map container co-ordinates to LatLng. I read that doing so requires creating a dummy overlay, and then using the getProjection() on that to get a MapCanvasProjection, and finally calling the fromContainerPixelToLatLng(). Is there any simpler way or do I really have to create a dummy overlay first?

allicarn
  • 2,859
  • 2
  • 28
  • 47
Jibran
  • 920
  • 9
  • 25
  • see at http://code.google.com/intl/vi/apis/maps/documentation/javascript/maptypes.html#Projections – nguyên Mar 16 '11 at 07:35

1 Answers1

1

As far as I can tell, this is the way you have to do it. I was reluctant at first, too, since it seemed like such overkill, but once I did it everything worked great. Here's an example implementation with a convenient delayedInit() callback:

function Dummy(map) {
    this.setMap(map);
}
Dummy.prototype = new google.maps.OverlayView();
Dummy.prototype.draw = function() {
    if (!this.ready) { 
        this.ready = true; 
        google.maps.event.trigger(this, 'ready'); 
    } 
}
Dummy.prototype.onAdd = function(){
    // the Overlay dummy is ready and can be called upon
    delayedInit();
}
var dum;

... and after you've instantiated your Google map:

dum = new Dummy(map);
vegemite4me
  • 6,621
  • 5
  • 53
  • 79
T3db0t
  • 3,491
  • 4
  • 28
  • 45
  • Thanks for that. I wound up in the same place after experimenting. Although, I just define the draw, onAdd and onRemove functions and leave them empty. Work like a charm! Thanks. – Jibran Nov 02 '10 at 13:39