Friday, 1 January 2010

How to browse Google Maps offline

(See also Crumbles: Maps Offline with Tile Viewer (part II), update Oct 2010)

Once I had a problem that I required my laptop to browse Google maps offline. I looked on the Internet but with no satisfying result. A simple task turned out to be quite complex.

My idea was to have abstract and reliable way to cache and reuse the online content - tiled images. Here what I tried first.

1. I wrote a crawler - a javascript program to force the browser crawl across a particular area. The input specifies latitude and longitude box and steps, zoom level, crawling speed, and satellite or map type.
2. I made my own web server to be used browser instead of going directly to the Internet. I set up 2 machines (one could be virtual). Edit 'hosts' file on the machine A with the list of servers I would like to make cache pointing to the IP address of machine B.
3. Machine B has to accept requests and re-request files from the Internet or retrieve from its cache. I wrote a simple program to do this task.
4. The program running on the machine B did not directly request the data from the Internet. Instead it used wget program. It was a simpler solution since wget allows more advanced way of downloading, e.g. using proxy.
5. Once the cache is full and ready the service program could be run on the machine A with no Internet.

This approach did not work quite well. First complication was that the browser opens simultaneously many connections and my server was one threaded and was not fast enough to serve all of them in timely manner. To overcome this problem I wrote a serialiser - a program getting many connections simultaneously, but requesting only one at a time while keeping others on hold. This worked somehow, but slowly - not to my satisfaction.

Finally I thought that I will download automatically tile images from Google using wget and later worry about viewing them. To my surprise after downloading tiles for about half an hour, I start getting response from the Google servers with the message something like "We are sorry but you are trying automatic downloading. To protect our customers we have to block your IP."

An even simpler solution had been required. I noticed that Microsoft Internet Explorer saves files in its cache directory with proper sub-address names. I wrote a simple program to rip the files from the cache recoding their names. Using Internet Explorer I navigated IE over desired area, and then ran the program and all necessary tiles were successfully stored at my place with proper cataloguing.

The last step was to cook a program (since I was not able to find appropriate application) to view the tiled images which I did very quickly and a bit dirty.

Here are the tile ripper and tile viewer for Windows http://mazonka.com/bin/gmrip.zip

I used this program when driving along Eastern Coast. The maps itself were on maximal resolution level 15 and occupied around 500Mb.

1 comment:

Anonymous said...

Good post and this post helped me alot in my college assignement. Gratefulness you for your information.