Over a million developers have joined DZone.

Converting Between 2 Google Map Tile Types

DZone's Guide to

Converting Between 2 Google Map Tile Types

· ·
Free Resource
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)
http://mt.google.com/mt?v=w2.5&x=20&y=49&zoom=10 (map)
http://kh.google.com/kh?v=3&t=tqtsqrqt (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 = 'http://kh.google.com/kh?v=3&t=' + quadtree(20,49,10)

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}