The file:
www.polyarc.us/adjust.js
contains conversion functions.
var offset=268435456;
var radius=offset/Math.PI;
function LToX(x)
{
return Math.round(offset+radius*x*Math.PI/180);
}
function LToY(y)
{
return Math.round(offset-radius*Math.log((1+Math.sin(y*Math.PI/180))/
(1-Math.sin(y*Math.PI/180)))/2);
}
function XToL(x)
{
return ((Math.round(x)-offset)/radius)*180/Math.PI;
}
function YToL(y)
{
return (Math.PI/2-2*Math.atan(Math.exp((Math.round(y)-offset)/
radius)))*180/Math.PI;
}
For a specific zoom level, you can shift the results of LToX & LToY by
(21-z).
xPixel = LToX(lng)>>(21-z);
yPixel = LToY(lat)>>(21-z);
The absolute pixel postions can be converted to relative pixel
positions with fixed X & Y offsets without repeated use of
"fromLatLngToDivPixel" which requires a new LatLng object for each
call. Just do it once for a known position like the center of the
map. The difference between absolute position & relative position
will not change unless the "offset" changes which will trigger another
event.