Pan point on Google Map to specific pixel position on screen (API v3)

Posted by Jake on Stack Overflow See other posts from Stack Overflow or by Jake
Published on 2010-05-06T01:25:10Z Indexed on 2010/05/06 1:28 UTC
Read the original article Hit count: 691

When overlay is a Google maps overlay and offsetx, offsety is the pixel distance from the maps center that I want to pan latlong to, the following works.

var projection = overlay.getProjection();
var pxlocation = projection.fromLatLngToContainerPixel(latlong);
map.panTo(projection.fromContainerPixelToLatLng(new google.maps.Point(pxlocation.x+offsetx,pxlocation.y+offsety)));

However, I don't always have an overlay on the map and map.getProjection() returns a projection, not a MapCanvasProjection which does not have the methods I need.

Is there a way to do this without making an overlay specificaly for it?

© Stack Overflow or respective owner

Related posts about google-maps

Related posts about google-maps-api