DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Converting Between 2 Google Map Tile Types

  • submit to reddit
        Google maps is a marvelous app.
I try to program a prototype of it on pys60

There I only show the default map, not the satellite images.
Retrieving a different mode isn't that difficult.
I read the info from here
Then I begin comparing the 2 tile types of the same area
(around California) (map) (satellite)

Here's the conversion routine between x,y,zoom and quadtree
def quadtree(x,y, zoom):
	out = []
	m = {(0,0):'q', (0,1):'t', (1,0):'r', (1,1):'s'}
	for i in range(17-zoom):
		x, rx = divmod(x, 2)
		y, ry = divmod(y, 2)
		out.insert(0, m[(rx,ry)])
	return 't' + ''.join(out)
Then to convert back
def xyzoom(quad):
	x, y, z = 0, 0, 17
	m = {'q':(0,0), 't':(0,1), 'r':(1,0), 's':(1,1)}
 	for c in quad[1:]:
		x = x*2 + m[c][0]
		y = y*2 + m[c][1]
		z -= 1
	return x, y, z
Using them is simple
>>> quadtree(20,49,10)
>>> xyzoom('tqtsqrqt')
(20, 49, 10)
>>> sat_url = '' + quadtree(20,49,10)