Thanks all,
The article on deconstructing google maps was interesting, but still a
bit far from what I needed to accomplish. I found the coordtotile.php
function separately, and I realized that it had what I needed (
http://mapki.com/coordtotile.2.phps - also found here:
http://mapki.com/wiki/Lat/Lon_To_Tile )
After some work I figured out how to get the info I needed out of it
by adding a short function. For anyone interested, I will paste it
below. This is a function that will spit out a wms query string (bbox
and xy coordinates) given a lat/lng pair and a google zoom. Just add
this to the end of coordtotile.2.php - then use the function
get_query_string($lat,$lng,$z). The only caveat is that coordtotile.
2.php does not seem to work well with zooms less than 8 (I imagine it
has something to do with crossing the zero longintude line, but I
didn't investigate further.)
Also, for anyone interested, coordtotile.2.php must have been
developed before google map switched their zoom around, because I had
to add -25 to the zoom so that the results match with current google
map zooms.
best,
nelson
<?
function get_query_string($lat,$lng,$z) {
$z = 25 - $z;
$tile = new Tile($lat,$lng,$z);
$tilelng = $tile->getTileLatLong();
$tilelng = $tilelng->x;
$tilelat = $tile->getTileLatLong();
$tilelat = $tilelat->y;
$tilelat2 = $tilelat;
$tilelng2 = $tilelng;
$lat2 = $lat;
$lng2 = $lng;
while($tilelat2 == $tilelat) {
$lat2 = $lat2 - .001;
$tile = new Tile($lat2,$lng2,$z);
$tilelat2 = $tile->getTileLatLong();
$tilelat2 = $tilelat2->y;
}
while($tilelng2 == $tilelng) {
$lng2 = $lng2 + .001;
$tile = new Tile($lat2,$lng2,$z);
$tilelng2 = $tile->getTileLatLong();
$tilelng2 = $tilelng2->x;
}
$thgt = $tilelat - $tilelat2;
$twdt = $tilelng2 - $tilelng;
$xpt = round(($lng-$tilelng)*256/$twdt);
$ypt = round(($tilelat-$lat)*256/$thgt);
$bbox = $tilelng.','.$tilelat2.','.$tilelng2.','.$tilelat;
$pt_coords = '&x='.$xpt.'&y='.$ypt;
$query = 'bbox='.$bbox.$pt_coords;
return $query;
}
?>
On Jan 18, 8:40 am, bratliff <bratl...@umich.edu> wrote:
> On Jan 18, 8:51 am, vasile cotovanu <vasile.cotov
...@gmail.com> wrote:
> > Read also here :http://cfis.savagexi.com/articles/2006/05/03/google-maps-deconstructed
> > The big magic it is in the projection formulas, Google uses a
> > different Mercator projection for each zoom level,
> huh ????
> The only difference is the shift amount (zoom parameter).
> http://www.polyarc.us/buildurl.js
> Look at the LToX & LToY functions. Ignore the "w" parameter which is
> the UTM zone. I stripped out the UTM projection stuff used by
> TerraServer.
> > after you will
> > define projection formulas you will can easily convert long/lat to
> > pixels(measure unit in projection used) for a given zoom level and
> > then to calculate the enclosing tile and of course top and left pixel
> > from 0,0 of tile.