For a while, I thought you might have found a bug in the Google APIs! ... but no, alas, that would be too easy; -)
Your main problem is that when you snap the div for your LatLngControl to the map, its width is 0. So it goes where it should be, and when you put the text in the div, it expands from that point. If you take the card and place it with the mouse, you will notice that LatLngControl will move according to how you planned. So quick fix, make this modification:
function LatLngControl(map) { this.node_ = this.createHtmlNode_(); var dmsLat = degToDms(map.getCenter().lat().toFixed(4)); var dmsLon = degToDms(map.getCenter().lng().toFixed(4)); this.node_.innerHTML = 'Mouse Position: ' + dmsLat + ', ' + dmsLon; map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(this.node_); this.setMap(map);
If you really want the page to load using latlng div invisible, you will need to work a little more - ultimately, the hack I think of is to programmatically pan the map back and forth when you first move the mouse over the map - for example when you shake the TV remote control so that it works fine ... but itβs not good.
Also this
position: absolute;
in your css is probably redundant. And so it is
divNode.index = 100;
... I know that you might try to place the latlng div above the Google ad unit so that it does not get obscured. And it can be done, but you have to attach the div to the page directly, and not through the map.
source share