Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i'm trying to implement the example .

When i'm implementing this with a Google map, I have a strange bug: the mouse pointer and the dot on the map are not in the same place.

Now if I change the line that in bold: map.addLayers([gmap,vectors]); to map.addLayers([wms,vectors]); everything works. (in other words I dont use google maps).

Can someone tell me what is happening?

Thanks in advance.

Here is my page and code:

<title>OpenLayers: Google Layer Example</title>

<script src=';v=2&amp;key=ABQIAAAAl9RMqSzhPUXAfeBCXOussRTQDbvAygy0cfGJr8dEMAYKf3RWNBQqP9mjKIsqTfmAlz5LOJ3Xpy5s4w'></script>

<script src=""></script>

<script type="text/javascript" >

   var map;
   var vectors;
   function initialize() {
       // Create the map object
       map = new OpenLayers.Map('map');
        //Create a Google layer
       var gmap = new OpenLayers.Layer.Google(
           "Google Streets", // the default
           {numZoomLevels: 20}
      // if i use this instead of gmap then everything works.
       var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                "", {layers: 'basic'});
       var renderer=OpenLayers.Util.getParameters(window.location.href).renderer;
       renderer=(renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;

       vectors= new OpenLayers.Layer.Vector("Vector Layer",{


       map.addControl(new OpenLayers.Control.LayerSwitcher());
       map.addControl(new OpenLayers.Control.MousePosition());

       var control=new OpenLayers.Control.DrawFeature(vectors,OpenLayers.Handler.Path);
       // Zoom to Vancouver, BC
       map.setCenter(new OpenLayers.LonLat(-123.12, 49.28), 13);         

<h1 id="title">OpenLayers: Google Layer Example</h1>

<div id="map" style="width:600px; height:400px"  class="smallmap"></div>

share|improve this question

It is not a bug

you need to set the projection correctly if using google maps with openlayers

    var map = new OpenLayers.Map("map", {
  projection: new OpenLayers.Projection("EPSG:900913")
var myBaseLayer = new OpenLayers.Layer.Google("Google",
              {'sphericalMercator': true,
               'maxExtent': new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
var myGML = new OpenLayers.Layer.GML("GML", "mygml.gml", {
  projection: new OpenLayers.Projection("EPSG:4326")

You will also need to set your vector layer (drag objects) to the correct projection or it will look offset. Example above uses GML.


share|improve this answer
yup thanks. i more or less hacked a solution for now. but for some reason i now get a new problem. I get a white dialogue: Google Maps (c) 2012 ... that appears on the screen. The strangest thing is that this does not happen all the time - just some times. i left a question here:… – jenia May 23 '12 at 15:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.