Thursday, April 07, 2005

Google Map

I was amazed at the way Google Maps works! It is way faster than Yahoo or MSN or MapQuest ( I think www.map.search.ch is equally fast, i like the zooming effect )

Google Maps uses two built-in browser components:
-> XMLHttpRequest ( very famous, used in Google Suggest) and
-> XSLTProcessor

Google Map communicates with the server to get the map tiles and search results
It basically gets 3 types of images from the server ( based on the selection)

1) JPEG Image in case of satellite image
It sends a GET request to Keyhole Server 2.4 at kh.google.com
Sample Get request
http://kh.google.com/kh?v=1&t=tqtrtsttrqqtrtq

Value of
v = No idea, seems to work with different values, maybe for some internal usage
t = direction to be taken to get the desired JPEG image tile










Q R
T S


-> t can have maximum 15 characters ( i.e 15 zoom levels)
-> suppose intially t = tqt ( so it will fetch 4 tiles, for top-left, top-right, bottom-left, bottom-right ) next time if t = tqtt , it means fetch the bottom-left tile and zoom it ( ie it will again fetch 4 more tiles )

2) GIF Image in case of map image
It sends a GET request to Keyhole Server 2.4 at mt.google.com
Sample Get request
http://mt.google.com/mt?v=.3&x=-2360&y=-1033&zoom=3
where,
v = No Idea
x = X coordinate of the tile to be fetched
y = Y coordinate of the tile to be fetched
zoom = zoom level ( 1 – 5 )
So it is possible to fetch the entire image database of Google maps, if we write a script which will fetch all image tiles for a given zoom level but obviously it is copyrighted!

3) PNG Image is returned which is basically the route between 2 locations (It is a white image with the route displayed in blue) and it is superimposed onto the image tiles.

It is again a GET request to Geocode/Map Server

Sample request:
http://www.google.com/maplinedraw?width=144&height=260&path={F{MGBGKZONVPVr@hA@@r@f@v@j@JFJJ?RQN?V?B?L?R@@?L?x@?ZA??JO?@LH??X}oR

where,
width/height = width/height of the resulting PNG file.
Path = yet to figure out ( i think the encoded string should contain the source and destination location ???? )

When we search for any city, say New York, it sends a HTTP GET request to mfe server. e.g.
http://maps.google.com/maps?q=new+york&btnG=Search&sll=33.748889%2C-84.388056&sspn=0.102539%2C0.230971&z=5&t=&f=q&output=js&hl=en

where,
q = name of the location
sll = latitude & longitude
sspn = span size
z = zoom level
the output of such a request is XML

<?xml version="1.0"?>
<page>
<title>new york</title>
<query>new york</query>
<request>
<url>
http://maps.google.com/maps?q=new+york&
btnG=Search&
sll=33.748889%2C-84.388056&
sspn=0.102539%2C0.230971&amp;amp;amp;amp;
z=5&
t=&
f=q&
hl=en&
num=10
</url>
<query>new york</query>
</request>
<center lat="40.714167" lng="-74.006389"/>
<span lat="0.089988" lng="-0.118722"/>
<overlay panelStyle="/maps?file=gp&hl=en">
<location infoStyle="/maps?file=gi&hl=en" id="A">
<point lat="40.714167" lng="-74.006389"/>
<icon class="noicon"/>
<info>
<address>
<line>
New York, NY
</line>
</address>
</info>
</location>
</overlay>
</page>

Location of XSL files
1) panelStyle = http://maps.google.com/maps?file=gp&hl=en
2) infoStyle = http://maps.google.com/maps?file=gi&hl=en


I read somewhere that this kind of apps are called AJAX ( Advanced Javascript & XML )

I personally think that Google might have pre-calculated routes between all locations ( if not all, atleast between important places). So when we try to find route between, say, A to B, Google would have precomputed it and would be in memory. So it can retrieve the path and send it back to the client.

One addition what Google could probably add is Traffic so that route displayed is the route with least traffic ( As I assume they have precomputed routes and put it in memory, assume 5 routes are there between A to B, all it has to do is to add weight ( traffic density) at run-time to all the 5 routes and return the route with the least traffic.

This is all I could manage to figure out in 2 hrs. Will post, once I find out more .