DivPixelToLatLng Google Maps V3 API not compatible

I need to place a marker at a fixed pixel location within the div of the map. To create a marker, you need LatLng. I understand that fromDivPixelToLatLng () is a way to convert from pixel coordinates to LatLng, but I can't make it behave sequentially.

I posted a simple example of my problem at http://www.pinksy.co.uk/newsquare/overlaytest.html . Click on the map to place the marker at 200px / 200px. Drag the map and click again. I expected the marker to be placed at 200px / 200px every time, but this is not the case.

First, I installed the map, as usual, in a 600px by 300px div:

var london = new google.maps.LatLng(51.501904,-0.130463);
var mapOptions = {
    zoom: 15,
    center: london,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

Then I create an overlay:

var overlay = new google.maps.OverlayView();
overlay.draw = function() {};
overlay.setMap(map);

fromDivPixelToLatLng(), click , 200px/200px. , , , 200px/200px:

google.maps.event.addListener(map, 'click', function(event) {

    var pixelLatLng = overlay.getProjection().fromDivPixelToLatLng(new google.maps.Point(200,200));

    var marker = new google.maps.Marker({
        position: pixelLatLng,
        map: map
    });
});

, , 200px/200px. ?

!

+5
2

, ContainerPixelToLatLng() - , . http://www.pinksy.co.uk/newsquare/overlaytest2.html.

( , fromDivPixelToLatLng , , !)

+3

: http://jsbin.com/otidih/51 . , - .

. :

ContainerPixel . , ContainerPixel LatLngs . ContainerPixel , (float), . , ContainerPixel mapCenter , :

overlay.getProjection().fromLatLngToContainerPixel(map.getCenter())

DivPixel Div, .

overlay.getProjection().fromLatLngToDivPixel(point)

() , DivPixel , , . , DivPixel , . .

, , DivPixel, reset , , LatLng DivPixel, .

,

map.getProjection().fromLatLngToPoint()

API LatLng , ( ). , LatLngs .

(0,0) - (85.0511287798066, -180) LatLng - Google Map ( , , )

+3

All Articles