Hi Karl,
My partner, Hussein Patni, and I have been hard at work trying to digest the new Google math!
The relevant Javascript code seems to be here:
http://maps.google.com/mapfiles/maps.8.xslt.js
(actually, there are a couple variations based on your browser, the appropriate file being chosen after a browser detect function runs. But, all the mapping math seems to be consistent (as makes sense) regardless of the exact Javascript file, so that one should work as well as any for "inspiration")
We determined that there is no scaling whatever on the longitude axis. There is a new style of scaling on the latitude axis, likely to handle polar-region "squishing" (since I work in Canada, Calgary specifically, I noticed the northern lats were way off right away ... the maps do seem to be nicer-looking than last generation).
Some rough pseudo-code for the new latitude scaling function looks like:
my $lat = shift; # contains desired latitude
# scaling factor
my $e = sin( $lat * pi/180 );
# bounds control
if ($e > 0.9999) {
$e = 0.9999;
} elsif ($e < 0.9999) {
$e = -0.9999;
}
my $bitmap_origin_y = GOOGLEMAPS_TILE_RES_Y * (0x20000 >> $zoom) / 2;
my $pix_per_lon_rad = GOOGLEMAPS_TILE_RES_Y * (0x20000 >> $zoom) / (2 * pi);
$ty = POSIX::floor( $bitmap_origin_y + 0.5 * log( (1+$e) / (1-$e) ) * -$pix_per_lon_rad );
$ty /= GOOGLEMAPS_TILE_RES_Y;
# $ty now contains the tile-float-y value for the given latitude
At initial glance, this plus changing a few constants in the package to handle the newer tile size and zoom levels seems to be producing accurate results, at least for my datasets.
I'm just about to try it with non-North American lat/long points to verify that it works elsewhere on the globe (as it *should*).
Once I test it a bit more and clean up the code I've been mangling (!!), I'll submit a patch and we can get an updated version of this on CPAN that works with the global maps!!
Cheers,
-Michael Burns
Cosbit Technologies