Version 4 (modified by crschmidt, 6 years ago)

--

Google Maps Failure

OpenLayers has, for a long time, used an internal assumption about the Google Maps API structure due to a lack of functionality in the API.

The behavior that OpenLayers depends on has changed, and is no longer the same. We have fixed this functionality in OpenLayers SVN, and it will be shortly released in OpenLayers 2.5 RC2.

If you are using an earlier OpenLayers release, you can work around the issue by adding the following code:

OpenLayers.Layer.Google.prototype.addContainerPxFunction=function() {
    if (typeof GMap2 != "undefined" && !GMap2.fromLatLngToContainerPixel) {
       
        GMap2.prototype.fromLatLngToContainerPixel = function(gLatLng) {
        
            // first we translate into "DivPixel"
            var gPoint = this.fromLatLngToDivPixel(gLatLng);
                
            // locate the sliding "Div" div
            var div = this.getContainer().firstChild.firstChild;
                
            // adjust by the offset of "Div" and voila!
            gPoint.x += div.offsetLeft;
            gPoint.y += div.offsetTop;
            
            return gPoint;
        };  
    }   
};  

This code snippet should be added *after* OpenLayers is loaded, but before any Google Layers are initialized. In general, this means it should be at the beginning of your initialization function which is called on loading of the page.

There is also a patch available:  http://trac.openlayers.org/attachment/ticket/994/google.patch

This patch is for 2.5, but applies cleanly to all previous copied of OpenLayers affected by the bug.

More information on this problem is available in #994, for interested parties.