Lat/Lon To Tile
From Google Mapki
[edit] Tools
The tools linked to here are designed to help you find image values for google's map tiles.
- First Version retrieves values for both map and satellite tiles.
- When you click on the included map the page will fetch the map and statellite tiles that correspond to that point.
- Second Version retrieves a grid of map tiles based on the point you click.
- The tool centers the grid of tiles on the tile clicked. You can specify the width of the tile grid you want. The tool also reports back the x, y, and zoom values for the center tile and the upper left corner tile. This is excellent for figuring out values for creating your own tiles, and is designed for use with the Automatic Tile Cutter script and the image serving script that is included in the Add Your Own Custom Map tutorial.
- Calculate the lat and long of tile boundaries at any zoom.
- A page that displays custom tiles that show the x,y,zoom (or satellite t=) parameters, and latitude and longitude of the tiles that make up a google map. The tiles are automatically generated so they are valid for the whole world. A small plain map overlay is provided to assist in navigation.
- Calculates virtually everything you'd want to know about tiles (GPL)
- A javascript version of the php Tile class below.
- A Python based clean and documented open-source script for calculating tile bounds, convert between WGS84 latlong coordinates, tiles, as well as meter and pixel coordinates is available at the website Google Maps Coordinate System Conversion, EPSG Projection and Tile Rendering. On that side is also an embedded Google Map which after click display the tile coordinates in several notations.
[edit] About Google's Tile Coordinate System
Google uses an x,y coordinate system combined with a zoom value to specify the tiles to retrieve from the server. These coordinates are calculated using an algorithm in JavaScript and passed along to the server to retrieve the images. The code for this algorithm can be found in the JavaScript API code and this implementation of the code was based on the original JavaScript.
Google Maps uses 256x256 pixel tiles for their map images.
Important: Scraping the tile images from Google's servers for any reason is against the terms of service and is not advised.
[edit] Source Code
The tools on this page use the Tile PHP class made by Ian Dees.
A rewritten, commented and enhanced version of the same class for PHP5: GMapTile
The source code can be viewed at this page.
<?php
//example of coordtotile.php use
include('coordtotile.php');
$latitude = 52.93568015098572;
$longitude = -0.7073771057190336;
$zoom = 1;
$tile = new Tile($latitude,$longitude,$zoom);
$tileX = $tile->getTileCoord();
$tileX = $tileX->x;
$tileY = $tile->getTileCoord();
$tileY = $tileY->y;
echo "X: ".$tileX.", Y: ".$tileY.", Z: ".$zoom;
?>
An alternative to the Tile PHP class mentioned above can be found in: GoogleTileUtils.java
A direct translation of coordtotile.php can be found at Tile.java and SimplePoint.java which can be used as:
import SimplePoint; import Tile; double lat = 51.749631; double lon = -1.240747; int zoom = 1; Tile t = new Tile(lat,lon,zoom); SimplePoint tileXY = t.getTileCoord(); int y = tileXY.getY(); int x = tileXY.getX();
