Wednesday, March 05, 2008

Download free maps from Google maps using Perl

The following is a step-by-step guide for downloading google maps to your harddisk and open it with your favourite image viewer.

Requirements:
1. Internet connection
2. Perl installed in your machine (Windows version available from http://www.activestate.com/store/freedownload.aspx?prdGuid=81fbce82-6bd5-49bc-a915-08d58c2648ca) In fact, you can use any scripting language you are conmfortable in.
3. Download wget executabel (Free windows version at http://users.ugent.be/~bpuype/cgi-bin/fetch.pl?dl=wget/wget.exe )
4. Irfanview image application (Free version at http://www.irfanview.com/main_download_engl.htm)

Procedure:
1. First go to http://maps.google.com and browse to the location you want to see.Move around in the map and in the bottom status window, you will see some thing like this:
http://mt3.google.com/mt?n=404&w=2.69&hl=en&x=54&y=108&zoom=9
2. Note this down. The value for x and y will depend on the location that you have browsed. The value of "zoom" will depend on your current zoom level. Also note down the values at the four corners of the area that you want to make a map of. Lets say thay are x varies from 1072 to 1090 and y varies from 600 to 900.
3. Using notepad open a file and type the following lines into it. Modify the $x1, $x2, $y1, $y2 ,$zoom and $step variables from step 2. Also modify the wget statement with the values of "n" and "w" from step 1:

#-------------------------------------
$x1=1072;
$x2=1090;
$y1=600;
$y2=900;
$zoom = 9;
$step = 1 ;
for($j=$y1;$j<=$y2;$j++) {
for($i=$x1;$i<=$x2;$i++) {
`wget -O $j.$i.png "http://mt3.google.com/mt?n=404&w=2.69&hl=en&x=$i&y=$j&zoom=$zoom"` ;
}
}
#-------------------------------------


4. Copy the "wget.exe" to the same directory as the above file.
5. Open command prompt , go to the same directory and type:
perl
6. The Perl will run and download all the images as small small tiles.
7. Open irfanview. Choose "Files->Thumbnails"
8. In the thumbnails window, choose all the png files which were downloaded earlier. Right click and choose "Create content sheet..."
9. In the dialog box, enter the image width , height etc using the values used above.
For eg, image width = (1090-1072+1)*256
image height = (900-600+1)*256
column width = (1090-1072+1)
row = (900-600+1)
Chooe spacing as 0.
10. Create the output, and that is your map file !!!!!

8 comments:

Krishna said...

Nice. However, it would be good if you can provide an exe which takes the url as the input and delivers the .png of the map as the output. What say?

ruzan said...

hi... nice work...
but honestly ... half of it went over my head
i want to download the india map to the max zoom.. i have downloaded and installed all software that u have mentioned.

can u please give me the data that u have used to download the india map? if u have already downloaded full india map in max zoom... than kindly share it in ogf2 format.

thanks...

sunnyvivi said...

I found these tools on this site.. are they helpful ? i am taking a look at it ! will use and post comment
http://www.mgmaps.com/cache/

trouble_monger said...

@sunnyvivi,
i saw those tools, and i had modified their perl scripts to save as png files. i might have it somewhere with me. i will post it as soon as i find out. the good thing about their script is that there is a userfriendly way of marking the map for the portion you want.

sunnyvivi said...

Thanks.. i tried my hand at scripts but they went rt above my head.. now trying my hands with the GUI stuff.. not much success there either as of tdy.. will wait for your program coz the maps you have posted are excellent :-)

Samarjit said...

Hello, Can I use these maps with Garmin GPS? If yes, you can I download these maps into my Garmin GPS device. Any response/ suggestions regading this topic will be appreciated.

-Samarjit

Debashis said...

Hi,
Thanks for all the GPS related articles.

I have one question. Can you tell me how can I download satellite images from WikiMapia? WikiMapia is having the most high resolution images I could find.

Thanks.

Skater said...

I must be missing something important. I don't have a status line (IE7) that has any text like you show in step 1.

I have the bottom status bar turned on but it is blank.

Is there something else that needs to be turned on?