<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.5" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Take Google Maps Offline</title>
	<link>http://kered.org/blog/2007-12-02/take-google-maps-offline/</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Fri, 21 Nov 2008 19:28:40 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>

	<item>
		<title>by: captainjc</title>
		<link>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-22813</link>
		<pubDate>Thu, 31 Jul 2008 22:44:35 +0000</pubDate>
		<guid>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-22813</guid>
					<description>current version is 2.80. that gets it to download the tiles, but still won't display. would be great if someone would update this to work with the new google maps code.</description>
		<content:encoded><![CDATA[<p>current version is 2.80. that gets it to download the tiles, but still won&#8217;t display. would be great if someone would update this to work with the new google maps code.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Lode</title>
		<link>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-22166</link>
		<pubDate>Thu, 17 Jul 2008 15:24:21 +0000</pubDate>
		<guid>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-22166</guid>
					<description>I also got the 'gapp is not defined' error. The images do work if you use this patch:


Index: ogmaps.py
===================================================================
--- ogmaps.py   (revision 8)
+++ ogmaps.py   (working copy)
@@ -31,6 +31,9 @@
 #        print 'already downloaded:', href
         return False
     else:
+        if not href.startswith('http://'):
+                href = 'http://maps.google.com' + href
+                print 'Fixed url :', href
         try:
             print 'downloading:', href
             oa = openanything.fetch(href)
@@ -84,8 +87,8 @@
 #    print 'x1,x2,y1,y2', x1f,x2f,y1f,y2f
     for x in range(x1f,x2f+1):
         for y in range(y1f,y2f+1):
-            href = 'http://mt%i.google.com/mt?n=404&#38;v=w2.63&#38;x=%i&#38;y=%i&#38;zoom=%i' % ((x+y)%4,x,y,zl)
-            filename = 'mt_n=404&#38;v=w2.63&#38;x=%i&#38;y=%i&#38;zoom=%i' % (x,y,zl)
+            href = 'http://mt%i.google.com/mt?n=404&#38;v=w2t.75&#38;x=%i&#38;y=%i&#38;zoom=%i' % ((x+y)%4,x,y,zl)
+            filename = 'mt_n=404&#38;v=w2t.75&#38;s=Galileo&#38;x=%i&#38;y=%i&#38;zoom=%i' % (x,y,zl)
             download_if_dne( href, os.path.join(RUN_FROM_DIR, 'data', 'tiles', filename) )</description>
		<content:encoded><![CDATA[<p>I also got the &#8216;gapp is not defined&#8217; error. The images do work if you use this patch:</p>
<p>Index: ogmaps.py<br />
===================================================================<br />
&#8212; ogmaps.py   (revision <img src='http://kered.org/blog/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /><br />
+++ ogmaps.py   (working copy)<br />
@@ -31,6 +31,9 @@<br />
 #        print &#8216;already downloaded:&#8217;, href<br />
         return False<br />
     else:<br />
+        if not href.startswith(&#8217;http://&#8217;):<br />
+                href = &#8216;http://maps.google.com&#8217; + href<br />
+                print &#8216;Fixed url :&#8217;, href<br />
         try:<br />
             print &#8216;downloading:&#8217;, href<br />
             oa = openanything.fetch(href)<br />
@@ -84,8 +87,8 @@<br />
 #    print &#8216;x1,x2,y1,y2&#8242;, x1f,x2f,y1f,y2f<br />
     for x in range(x1f,x2f+1):<br />
         for y in range(y1f,y2f+1):<br />
-            href = &#8216;http://mt%i.google.com/mt?n=404&amp;v=w2.63&amp;x=%i&amp;y=%i&amp;zoom=%i&#8217; % ((x+y)%4,x,y,zl)<br />
-            filename = &#8216;mt_n=404&amp;v=w2.63&amp;x=%i&amp;y=%i&amp;zoom=%i&#8217; % (x,y,zl)<br />
+            href = &#8216;http://mt%i.google.com/mt?n=404&amp;v=w2t.75&amp;x=%i&amp;y=%i&amp;zoom=%i&#8217; % ((x+y)%4,x,y,zl)<br />
+            filename = &#8216;mt_n=404&amp;v=w2t.75&amp;s=Galileo&amp;x=%i&amp;y=%i&amp;zoom=%i&#8217; % (x,y,zl)<br />
             download_if_dne( href, os.path.join(RUN_FROM_DIR, &#8216;data&#8217;, &#8217;tiles&#8217;, filename) )
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: FreakyT</title>
		<link>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-21808</link>
		<pubDate>Mon, 07 Jul 2008 17:52:08 +0000</pubDate>
		<guid>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-21808</guid>
					<description>I tried it, most of the images failed to download (blur's fix managed to get it to download the tiles, but that didn't help), and I also get a "gapp is not defined" error.  Any chance of a fix?</description>
		<content:encoded><![CDATA[<p>I tried it, most of the images failed to download (blur&#8217;s fix managed to get it to download the tiles, but that didn&#8217;t help), and I also get a &#8220;gapp is not defined&#8221; error.  Any chance of a fix?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: blur</title>
		<link>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-21398</link>
		<pubDate>Fri, 27 Jun 2008 07:05:46 +0000</pubDate>
		<guid>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-21398</guid>
					<description>&lt;code&gt;
#!/usr/bin/env python

#    OGMaps
#    Copyright (C) 2007 Derek Anderson
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import math, os, re, sys, urllib

RUN_FROM_DIR = os.path.abspath(os.path.dirname(sys.argv[0])) + '/'
DEFAULT_MAX_SPAN = 12

from BeautifulSoup import BeautifulSoup
import openanything


def download_if_dne(href, filename):
    if os.path.isfile(filename):
#        print 'already downloaded:', href
        return False
    else:
        try:
            if href[0:7]!='http://' : href = 'http://maps.google.com'+href
            print 'downloading:', href
            oa = openanything.fetch(href)
            if oa['status']==200:
                file = open( filename, 'wb' )
                file.write( oa['data'] )
                file.close()
            return True
        except KeyboardInterrupt:
            raise
        except:
            print '\tdownload failed -', sys.exc_info()[0]
            return False
            
def hide_if_found(o):
    if o:
        o['style'] = 'display:none;'

def get_tile_coords(lat, lng, zl): 
    tile_width = 256
    max_zoom_level = 17
    
    map_size = 2**((max_zoom_level + (math.log(tile_width)/math.log(2)))-zl)
    lng_degrees = abs(-180 - lng)
    lng_ppd = map_size / 360
    lng_ppd_radians = map_size/(2*math.pi)
    e = math.sin(lat*(1/180.*math.pi))
    if e&#62;0.9999: e=0.9999
    if e max_span:
        x1f = (x1+x2)/2-max_span/2; x2f = (x1+x2)/2+max_span/2
    else:
        x1f, x2f = x1, x2
    if y2-y1 &#62; max_span:
        y1f = (y1+y2)/2-max_span/2; y2f = (y1+y2)/2+max_span/2
    else:
        y1f, y2f = y1, y2
        
#    print 'x1,x2,y1,y2', x1f,x2f,y1f,y2f
    for x in range(x1f,x2f+1):
        for y in range(y1f,y2f+1):
            href = 'http://mt%i.google.com/mt?n=404&#38;v=w2.75&#38;x=%i&#38;y=%i&#38;zoom=%i' % ((x+y)%4,x,y,zl)
            filename = 'mt_n=404&#38;v=w2.75&#38;x=%i&#38;y=%i&#38;zoom=%i' % (x,y,zl)
            download_if_dne( href, os.path.join(RUN_FROM_DIR, 'data', 'tiles', filename) )

def download(location=None, max_span=DEFAULT_MAX_SPAN):
    
    # init dirs
    for dir in [ 'data', os.path.join('data','tiles') ]:
        if not os.path.isdir(dir):
            os.mkdir(dir)

    # download the base page
    if location:
        print 'downloading the following location:', location
        oa = openanything.fetch( 'http://maps.google.com/maps?q='+urllib.quote_plus(location) )
    else:
        print 'downloading the default world map'
        oa = openanything.fetch('http://maps.google.com')
    if oa['status']!=200:
        print 'error connecting to http://maps.google.com - aborting'
        return
    html = oa['data']
    
    # find our loc,lat,lng
    p = re.compile('laddr:"([^"]+)"')
    m = p.search(html)
    if m:
        location = m.group(1)
        print '\tlocation =',location
    else:
        if location:
            print '\tlocation not found - aborting'
            return
    p = re.compile('center:{lat:([0-9.-]+),lng:([0-9.-]+)}')
    m = p.search(html)
    if m:
        lat, lng = float(m.group(1)), float(m.group(2))
    else:
        lat, lng = 37.0625,-95.677068
    print '\tlatitude, longitude = %f, %f' % (lat, lng)
    
    # find our zoom level
    p = re.compile('span:{lat:([0-9.]+),lng:([0-9.]+)}')
    m = p.search(html)
    if m:
        span_lat, span_lng = float(m.group(1)), float(m.group(2))
    else:
        span_lat, span_lng = 32, 64
    print '\tspan-latitude, span-longitude = %f, %f' % (span_lat, span_lng)
    
    mapfiles = 'http://www.google.com/intl/en_All/mapfiles/117/maps2'

    # perform some base transformations
    html = html.replace('&#160;', '') # beautifulsoup doesn't like this char
    html = html.replace('window.document.title = vPage.title;', 'window.document.title = "Offline Google Maps - http://code.google.com/p/ogmaps/";')
    html = html.replace('http://mt0.google.com/mt?', 'data\\x2ftiles\\x2fmt?')
    html = html.replace('http://mt1.google.com/mt?', 'data\\x2ftiles\\x2fmt?')
    html = html.replace('http://mt2.google.com/mt?', 'data\\x2ftiles\\x2fmt?')
    html = html.replace('http://mt3.google.com/mt?', 'data\\x2ftiles\\x2fmt?')
    html = html.replace('body{margin-top: 3px;margin-bottom: 0;margin-left: 8px;}', 'body{margin:0px;}')
    html = html.replace('#map {left: 20em;margin-left: 8px;margin-right: 20em;', '#map {')
    html = html.replace('var height = getWindowHeight() - offsetTop - 10;', 'var height = getWindowHeight() - offsetTop;')
    
    # get our kitchen
    soup = BeautifulSoup(html)

    hide_if_found( soup.find('div', attrs={'id':'header'}) )
    hide_if_found( soup.find('div', attrs={'id':'guser'}) )
    hide_if_found( soup.find('div', attrs={'id':'gbar'}) )
    hide_if_found( soup.find('div', attrs={'id':'gbh'}) )
    hide_if_found( soup.find('div', attrs={'id':'hp'}) )
    hide_if_found( soup.find('div', attrs={'id':'panel'}) )
    hide_if_found( soup.find('a', attrs={'id':'paneltoggle'}) )

    o = soup.find('div', attrs={'id':'actions'})
    if o:
        o['style'] = 'display:none;'

    # get main.js and transmogrify
    if not os.path.isfile(os.path.join(RUN_FROM_DIR, 'data', 'main.js')):
        print 'downloading:', mapfiles+'/main.js'
        oa = openanything.fetch(mapfiles+'/main.js')
        js = oa['data']
        js = js.replace('function rf(a,b){','function rf(a,b){b = b.replace("tiles/mt?","tiles/mt_");')
        js = js.replace('mb("/maps/gen_204?ev=failed_tile&#38;cad="+f)','mb("data/transparent.png")')
        js = js.replace('document.body.style[Nk]=$(0);document.body.style[Fe]=$(8)','')
        js = js.replace('this.u.id="hmtctl";','this.u.id="hmtctl";this.u.style.display="none";')
        file = open( os.path.join(RUN_FROM_DIR, 'data', 'main.js'), 'w' )
        file.write( js )
        file.close()
    
    # get mod_cb.js and transmogrify
    if not os.path.isfile(os.path.join(RUN_FROM_DIR, 'data', 'mod_cb.js')):
        print 'downloading:', mapfiles+'/mod_cb.js'
        oa = openanything.fetch(mapfiles+'/mod_cb.js')
        js = oa['data']
        js = js.replace('/mapfiles/cb','data')
        js = js.replace('c.id="cbcontrol";','c.id="cbcontrol";c.style.display="none;";')
        file = open( os.path.join(RUN_FROM_DIR, 'data', 'mod_cb.js'), 'w' )
        file.write( js )
        file.close()
    
    # get mod_traffic_app.js and transmogrify
    if not os.path.isfile(os.path.join(RUN_FROM_DIR, 'data', 'mod_traffic_app.js')):
        print 'downloading:', mapfiles+'/mod_traffic_app.js'
        oa = openanything.fetch(mapfiles+'/mod_traffic_app.js')
        js = oa['data']
        js = js.replace('/maps/tldata','data/tldata')
        file = open( os.path.join(RUN_FROM_DIR, 'data', 'mod_traffic_app.js'), 'w' )
        file.write( js )
        file.close()
    
    # get mod_ms.js and transmogrify
    if not os.path.isfile(os.path.join(RUN_FROM_DIR, 'data', 'mod_ms.js')):
        print 'downloading:', mapfiles+'/mod_ms.js'
        oa = openanything.fetch(mapfiles+'/mod_ms.js')
        js = oa['data']
        js = js.replace('http://maps.google.com','data')
        js = js.replace('/mapfiles','')
        file = open( os.path.join(RUN_FROM_DIR, 'data', 'mod_ms.js'), 'w' )
        file.write( js )
        file.close()
    
    # get other scripts
    scripts = [ 'mod_mymaps.js', 'mod_mpl_host.js', 'mod_kml.js', 'mod_le.js', 'mod_lyrsctrl.js','mod_trends.js', 'mod_infowindow.js']
    for s in scripts:
        download_if_dne( mapfiles+'/'+s, os.path.join(RUN_FROM_DIR, 'data', s) )
    
    # get linked scripts
    for tag in soup.findAll('link'):
        try:
            href = tag['href']
            filename = href.split('/')[-1]
            download_if_dne( href, os.path.join(RUN_FROM_DIR, 'data', filename) )
            tag['href'] = 'data/'+filename
        except:
            print 'error:', tag

    # get all static images
    for tag in soup.findAll('img'):
        try:
            src = tag['src']
            filename = src.split('/')[-1]
            download_if_dne( src, os.path.join(RUN_FROM_DIR, 'data', filename) )
            tag['src'] = 'data/'+filename
        except:
            # print 'error:', tag
            pass
    
    # get other misc files
    download_if_dne( 'http://www.google.com/mapfiles/cb/bounds_cippppt.txt', os.path.join(RUN_FROM_DIR, 'data', 'bounds_cippppt.txt') )
    download_if_dne( 'http://maps.google.com/maps/tldata?tldtype=1&#38;hl=en&#38;country=us&#38;callback=_xdc_._1f9onnphn', os.path.join(RUN_FROM_DIR, 'data', 'tldata') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/arrow-white.png', os.path.join(RUN_FROM_DIR, 'data', 'arrow-white.png') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/arrow.png', os.path.join(RUN_FROM_DIR, 'data', 'arrow.png') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/lmc.png', os.path.join(RUN_FROM_DIR, 'data', 'lmc.png') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/lmc-bottom.png', os.path.join(RUN_FROM_DIR, 'data', 'lmc-bottom.png') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/slider.png', os.path.join(RUN_FROM_DIR, 'data', 'slider.png') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/scale.png', os.path.join(RUN_FROM_DIR, 'data', 'scale.png') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/arrowtransparent.png', os.path.join(RUN_FROM_DIR, 'data', 'arrowtransparent.png') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/overcontract.gif', os.path.join(RUN_FROM_DIR, 'data', 'overcontract.gif') )
    download_if_dne( 'http://maps.google.com/mapfiles/etna.jpg', os.path.join(RUN_FROM_DIR, 'data', 'etna.jpg') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/drag_cross_67_16.png', os.path.join(RUN_FROM_DIR, 'data', 'drag_cross_67_16.png') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/iws2.png', os.path.join(RUN_FROM_DIR, 'data', 'iws2.png') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/iw2.png', os.path.join(RUN_FROM_DIR, 'data', 'iw2.png') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/iw_close.gif', os.path.join(RUN_FROM_DIR, 'data', 'iw_close.gif') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/iw_plus.gif', os.path.join(RUN_FROM_DIR, 'data', 'iw_plus.gif') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/iw_fullscreen.gif', os.path.join(RUN_FROM_DIR, 'data', 'iw_fullscreen.gif') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/iw_minus.gif', os.path.join(RUN_FROM_DIR, 'data', 'iw_minus.gif') )
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/transparent.gif', os.path.join(RUN_FROM_DIR, 'data', 'transparent.gif') )
#    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/', os.path.join(RUN_FROM_DIR, 'data', '') )
    
            
    # some post transformations, then write to disk
    html = soup.prettify()
    html = html.replace(mapfiles, 'data')
    html = html.replace('http://www.google.com/intl/en_All/mapfiles', 'data')
    html = html + 'div.contextmenu {display:none;}'

    html = html.replace('/intl/en_ALL/mapfiles/117/maps2','./data')
    html = html.replace('/intl/en_ALL/mapfiles/','./data/')
    html = html.replace('_mStaticPath+\'/cb','_mStaticPath+\'/')
    
    file = open( os.path.join(RUN_FROM_DIR, 'ogmap.html'), 'w')
    file.write( html )
    file.close()
    #print html

    # get map data
    for zl in range(17,0,-1):
        get_map_data( get_tile_coords( lat-span_lat, lng-span_lng, zl ), get_tile_coords( lat+span_lat, lng+span_lng, zl ), zl, max_span )
    
    print '\nyour offline google map is ready at:', RUN_FROM_DIR+'ogmap.html'



if __name__ == "__main__":
    max_span = DEFAULT_MAX_SPAN
    locations = []
    if len(sys.argv)&#62;1:
        for arg in sys.argv[1:]:
            if arg.startswith('--'):
                if arg.startswith('--max-span='):
                    max_span = int(arg[11:])
                    print 'using max_span =', max_span
            else:
                locations.append(arg)

    if not len(locations):
        download(None, max_span)
    else:
        for location in locations:
            download(location, max_span)
&lt;/code&gt;

this is my modified version to avoid those errors.
no error any more, and tiles downloaded. 

but still nothing on the map.</description>
		<content:encoded><![CDATA[<p><code><br />
#!/usr/bin/env python</p>
<p>#    OGMaps<br />
#    Copyright (C) 2007 Derek Anderson<br />
#<br />
#    This program is free software; you can redistribute it and/or modify<br />
#    it under the terms of the GNU General Public License as published by<br />
#    the Free Software Foundation; either version 2 of the License, or<br />
#    (at your option) any later version.<br />
#<br />
#    This program is distributed in the hope that it will be useful,<br />
#    but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br />
#    GNU General Public License for more details.<br />
#<br />
#    You should have received a copy of the GNU General Public License along<br />
#    with this program; if not, write to the Free Software Foundation, Inc.,<br />
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.</p>
<p>import math, os, re, sys, urllib</p>
<p>RUN_FROM_DIR = os.path.abspath(os.path.dirname(sys.argv[0])) + '/'<br />
DEFAULT_MAX_SPAN = 12</p>
<p>from BeautifulSoup import BeautifulSoup<br />
import openanything</p>
<p>def download_if_dne(href, filename):<br />
    if os.path.isfile(filename):<br />
#        print 'already downloaded:', href<br />
        return False<br />
    else:<br />
        try:<br />
            if href[0:7]!='http://' : href = 'http://maps.google.com'+href<br />
            print 'downloading:', href<br />
            oa = openanything.fetch(href)<br />
            if oa['status']==200:<br />
                file = open( filename, 'wb' )<br />
                file.write( oa['data'] )<br />
                file.close()<br />
            return True<br />
        except KeyboardInterrupt:<br />
            raise<br />
        except:<br />
            print '\tdownload failed -', sys.exc_info()[0]<br />
            return False</p>
<p>def hide_if_found(o):<br />
    if o:<br />
        o['style'] = 'display:none;'</p>
<p>def get_tile_coords(lat, lng, zl):<br />
    tile_width = 256<br />
    max_zoom_level = 17</p>
<p>    map_size = 2**((max_zoom_level + (math.log(tile_width)/math.log(2)))-zl)<br />
    lng_degrees = abs(-180 - lng)<br />
    lng_ppd = map_size / 360<br />
    lng_ppd_radians = map_size/(2*math.pi)<br />
    e = math.sin(lat*(1/180.*math.pi))<br />
    if e&gt;0.9999: e=0.9999<br />
    if e max_span:<br />
        x1f = (x1+x2)/2-max_span/2; x2f = (x1+x2)/2+max_span/2<br />
    else:<br />
        x1f, x2f = x1, x2<br />
    if y2-y1 &gt; max_span:<br />
        y1f = (y1+y2)/2-max_span/2; y2f = (y1+y2)/2+max_span/2<br />
    else:<br />
        y1f, y2f = y1, y2</p>
<p>#    print 'x1,x2,y1,y2', x1f,x2f,y1f,y2f<br />
    for x in range(x1f,x2f+1):<br />
        for y in range(y1f,y2f+1):<br />
            href = 'http://mt%i.google.com/mt?n=404&amp;v=w2.75&amp;x=%i&amp;y=%i&amp;zoom=%i' % ((x+y)%4,x,y,zl)<br />
            filename = 'mt_n=404&amp;v=w2.75&amp;x=%i&amp;y=%i&amp;zoom=%i' % (x,y,zl)<br />
            download_if_dne( href, os.path.join(RUN_FROM_DIR, 'data', 'tiles', filename) )</p>
<p>def download(location=None, max_span=DEFAULT_MAX_SPAN):</p>
<p>    # init dirs<br />
    for dir in [ 'data', os.path.join('data','tiles') ]:<br />
        if not os.path.isdir(dir):<br />
            os.mkdir(dir)</p>
<p>    # download the base page<br />
    if location:<br />
        print 'downloading the following location:', location<br />
        oa = openanything.fetch( 'http://maps.google.com/maps?q='+urllib.quote_plus(location) )<br />
    else:<br />
        print 'downloading the default world map'<br />
        oa = openanything.fetch('http://maps.google.com')<br />
    if oa['status']!=200:<br />
        print 'error connecting to <a href="http://maps.google.com" rel="nofollow">http://maps.google.com</a> - aborting'<br />
        return<br />
    html = oa['data']</p>
<p>    # find our loc,lat,lng<br />
    p = re.compile('laddr:"([^"]+)"')<br />
    m = p.search(html)<br />
    if m:<br />
        location = m.group(1)<br />
        print '\tlocation =',location<br />
    else:<br />
        if location:<br />
            print '\tlocation not found - aborting'<br />
            return<br />
    p = re.compile('center:{lat:([0-9.-]+),lng:([0-9.-]+)}')<br />
    m = p.search(html)<br />
    if m:<br />
        lat, lng = float(m.group(1)), float(m.group(2))<br />
    else:<br />
        lat, lng = 37.0625,-95.677068<br />
    print '\tlatitude, longitude = %f, %f' % (lat, lng)</p>
<p>    # find our zoom level<br />
    p = re.compile('span:{lat:([0-9.]+),lng:([0-9.]+)}')<br />
    m = p.search(html)<br />
    if m:<br />
        span_lat, span_lng = float(m.group(1)), float(m.group(2))<br />
    else:<br />
        span_lat, span_lng = 32, 64<br />
    print '\tspan-latitude, span-longitude = %f, %f' % (span_lat, span_lng)</p>
<p>    mapfiles = 'http://www.google.com/intl/en_All/mapfiles/117/maps2'</p>
<p>    # perform some base transformations<br />
    html = html.replace('&#160;', '') # beautifulsoup doesn't like this char<br />
    html = html.replace('window.document.title = vPage.title;', 'window.document.title = "Offline Google Maps - <a href="http://code.google.com/p/ogmaps/" rel="nofollow">http://code.google.com/p/ogmaps/</a>";')<br />
    html = html.replace('http://mt0.google.com/mt?', 'data\\x2ftiles\\x2fmt?')<br />
    html = html.replace('http://mt1.google.com/mt?', 'data\\x2ftiles\\x2fmt?')<br />
    html = html.replace('http://mt2.google.com/mt?', 'data\\x2ftiles\\x2fmt?')<br />
    html = html.replace('http://mt3.google.com/mt?', 'data\\x2ftiles\\x2fmt?')<br />
    html = html.replace('body{margin-top: 3px;margin-bottom: 0;margin-left: 8px;}', 'body{margin:0px;}')<br />
    html = html.replace('#map {left: 20em;margin-left: 8px;margin-right: 20em;', '#map {')<br />
    html = html.replace('var height = getWindowHeight() - offsetTop - 10;', 'var height = getWindowHeight() - offsetTop;')</p>
<p>    # get our kitchen<br />
    soup = BeautifulSoup(html)</p>
<p>    hide_if_found( soup.find('div', attrs={'id':'header'}) )<br />
    hide_if_found( soup.find('div', attrs={'id':'guser'}) )<br />
    hide_if_found( soup.find('div', attrs={'id':'gbar'}) )<br />
    hide_if_found( soup.find('div', attrs={'id':'gbh'}) )<br />
    hide_if_found( soup.find('div', attrs={'id':'hp'}) )<br />
    hide_if_found( soup.find('div', attrs={'id':'panel'}) )<br />
    hide_if_found( soup.find('a', attrs={'id':'paneltoggle'}) )</p>
<p>    o = soup.find('div', attrs={'id':'actions'})<br />
    if o:<br />
        o['style'] = 'display:none;'</p>
<p>    # get main.js and transmogrify<br />
    if not os.path.isfile(os.path.join(RUN_FROM_DIR, 'data', 'main.js')):<br />
        print 'downloading:', mapfiles+'/main.js'<br />
        oa = openanything.fetch(mapfiles+'/main.js')<br />
        js = oa['data']<br />
        js = js.replace('function rf(a,b){','function rf(a,b){b = b.replace("tiles/mt?","tiles/mt_");')<br />
        js = js.replace('mb("/maps/gen_204?ev=failed_tile&amp;cad="+f)','mb("data/transparent.png")')<br />
        js = js.replace('document.body.style[Nk]=$(0);document.body.style[Fe]=$(8)','')<br />
        js = js.replace('this.u.id="hmtctl";','this.u.id="hmtctl";this.u.style.display="none";')<br />
        file = open( os.path.join(RUN_FROM_DIR, 'data', 'main.js'), 'w' )<br />
        file.write( js )<br />
        file.close()</p>
<p>    # get mod_cb.js and transmogrify<br />
    if not os.path.isfile(os.path.join(RUN_FROM_DIR, 'data', 'mod_cb.js')):<br />
        print 'downloading:', mapfiles+'/mod_cb.js'<br />
        oa = openanything.fetch(mapfiles+'/mod_cb.js')<br />
        js = oa['data']<br />
        js = js.replace('/mapfiles/cb','data')<br />
        js = js.replace('c.id="cbcontrol";','c.id="cbcontrol";c.style.display="none;";')<br />
        file = open( os.path.join(RUN_FROM_DIR, 'data', 'mod_cb.js'), 'w' )<br />
        file.write( js )<br />
        file.close()</p>
<p>    # get mod_traffic_app.js and transmogrify<br />
    if not os.path.isfile(os.path.join(RUN_FROM_DIR, 'data', 'mod_traffic_app.js')):<br />
        print 'downloading:', mapfiles+'/mod_traffic_app.js'<br />
        oa = openanything.fetch(mapfiles+'/mod_traffic_app.js')<br />
        js = oa['data']<br />
        js = js.replace('/maps/tldata','data/tldata')<br />
        file = open( os.path.join(RUN_FROM_DIR, 'data', 'mod_traffic_app.js'), 'w' )<br />
        file.write( js )<br />
        file.close()</p>
<p>    # get mod_ms.js and transmogrify<br />
    if not os.path.isfile(os.path.join(RUN_FROM_DIR, 'data', 'mod_ms.js')):<br />
        print 'downloading:', mapfiles+'/mod_ms.js'<br />
        oa = openanything.fetch(mapfiles+'/mod_ms.js')<br />
        js = oa['data']<br />
        js = js.replace('http://maps.google.com','data')<br />
        js = js.replace('/mapfiles','')<br />
        file = open( os.path.join(RUN_FROM_DIR, 'data', 'mod_ms.js'), 'w' )<br />
        file.write( js )<br />
        file.close()</p>
<p>    # get other scripts<br />
    scripts = [ 'mod_mymaps.js', 'mod_mpl_host.js', 'mod_kml.js', 'mod_le.js', 'mod_lyrsctrl.js','mod_trends.js', 'mod_infowindow.js']<br />
    for s in scripts:<br />
        download_if_dne( mapfiles+'/'+s, os.path.join(RUN_FROM_DIR, 'data', s) )</p>
<p>    # get linked scripts<br />
    for tag in soup.findAll('link'):<br />
        try:<br />
            href = tag['href']<br />
            filename = href.split('/')[-1]<br />
            download_if_dne( href, os.path.join(RUN_FROM_DIR, 'data', filename) )<br />
            tag['href'] = 'data/'+filename<br />
        except:<br />
            print 'error:', tag</p>
<p>    # get all static images<br />
    for tag in soup.findAll('img'):<br />
        try:<br />
            src = tag['src']<br />
            filename = src.split('/')[-1]<br />
            download_if_dne( src, os.path.join(RUN_FROM_DIR, 'data', filename) )<br />
            tag['src'] = 'data/'+filename<br />
        except:<br />
            # print 'error:', tag<br />
            pass</p>
<p>    # get other misc files<br />
    download_if_dne( 'http://www.google.com/mapfiles/cb/bounds_cippppt.txt', os.path.join(RUN_FROM_DIR, 'data', 'bounds_cippppt.txt') )<br />
    download_if_dne( 'http://maps.google.com/maps/tldata?tldtype=1&amp;hl=en&amp;country=us&amp;callback=_xdc_._1f9onnphn', os.path.join(RUN_FROM_DIR, 'data', 'tldata') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/arrow-white.png', os.path.join(RUN_FROM_DIR, 'data', 'arrow-white.png') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/arrow.png', os.path.join(RUN_FROM_DIR, 'data', 'arrow.png') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/lmc.png', os.path.join(RUN_FROM_DIR, 'data', 'lmc.png') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/lmc-bottom.png', os.path.join(RUN_FROM_DIR, 'data', 'lmc-bottom.png') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/slider.png', os.path.join(RUN_FROM_DIR, 'data', 'slider.png') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/scale.png', os.path.join(RUN_FROM_DIR, 'data', 'scale.png') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/arrowtransparent.png', os.path.join(RUN_FROM_DIR, 'data', 'arrowtransparent.png') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/overcontract.gif', os.path.join(RUN_FROM_DIR, 'data', 'overcontract.gif') )<br />
    download_if_dne( 'http://maps.google.com/mapfiles/etna.jpg', os.path.join(RUN_FROM_DIR, 'data', 'etna.jpg') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/drag_cross_67_16.png', os.path.join(RUN_FROM_DIR, 'data', 'drag_cross_67_16.png') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/iws2.png', os.path.join(RUN_FROM_DIR, 'data', 'iws2.png') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/iw2.png', os.path.join(RUN_FROM_DIR, 'data', 'iw2.png') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/iw_close.gif', os.path.join(RUN_FROM_DIR, 'data', 'iw_close.gif') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/iw_plus.gif', os.path.join(RUN_FROM_DIR, 'data', 'iw_plus.gif') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/iw_fullscreen.gif', os.path.join(RUN_FROM_DIR, 'data', 'iw_fullscreen.gif') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/iw_minus.gif', os.path.join(RUN_FROM_DIR, 'data', 'iw_minus.gif') )<br />
    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/transparent.gif', os.path.join(RUN_FROM_DIR, 'data', 'transparent.gif') )<br />
#    download_if_dne( 'http://www.google.com/intl/en_All/mapfiles/', os.path.join(RUN_FROM_DIR, 'data', '') )</p>
<p>    # some post transformations, then write to disk<br />
    html = soup.prettify()<br />
    html = html.replace(mapfiles, 'data')<br />
    html = html.replace('http://www.google.com/intl/en_All/mapfiles', 'data')<br />
    html = html + 'div.contextmenu {display:none;}'</p>
<p>    html = html.replace('/intl/en_ALL/mapfiles/117/maps2','./data')<br />
    html = html.replace('/intl/en_ALL/mapfiles/','./data/')<br />
    html = html.replace('_mStaticPath+\'/cb','_mStaticPath+\'/')</p>
<p>    file = open( os.path.join(RUN_FROM_DIR, 'ogmap.html'), 'w')<br />
    file.write( html )<br />
    file.close()<br />
    #print html</p>
<p>    # get map data<br />
    for zl in range(17,0,-1):<br />
        get_map_data( get_tile_coords( lat-span_lat, lng-span_lng, zl ), get_tile_coords( lat+span_lat, lng+span_lng, zl ), zl, max_span )</p>
<p>    print '\nyour offline google map is ready at:', RUN_FROM_DIR+'ogmap.html'</p>
<p>if __name__ == "__main__":<br />
    max_span = DEFAULT_MAX_SPAN<br />
    locations = []<br />
    if len(sys.argv)&gt;1:<br />
        for arg in sys.argv[1:]:<br />
            if arg.startswith('--'):<br />
                if arg.startswith('--max-span='):<br />
                    max_span = int(arg[11:])<br />
                    print 'using max_span =', max_span<br />
            else:<br />
                locations.append(arg)</p>
<p>    if not len(locations):<br />
        download(None, max_span)<br />
    else:<br />
        for location in locations:<br />
            download(location, max_span)<br />
</code></p>
<p>this is my modified version to avoid those errors.<br />
no error any more, and tiles downloaded. </p>
<p>but still nothing on the map.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: blur</title>
		<link>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-21390</link>
		<pubDate>Fri, 27 Jun 2008 05:11:47 +0000</pubDate>
		<guid>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-21390</guid>
					<description>if the tiles not downloaded. try change the line 87 and 88 of ogmaps.py from v=w2.63 to v=w2.75.</description>
		<content:encoded><![CDATA[<p>if the tiles not downloaded. try change the line 87 and 88 of ogmaps.py from v=w2.63 to v=w2.75.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Wafflematt</title>
		<link>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-20829</link>
		<pubDate>Mon, 09 Jun 2008 01:45:37 +0000</pubDate>
		<guid>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-20829</guid>
					<description>Downloaded today, and I get a javascript error when running it (gapp is not defined).
Map tile data did download.

Posted a bug on google code.

I'd like this to work...</description>
		<content:encoded><![CDATA[<p>Downloaded today, and I get a javascript error when running it (gapp is not defined).<br />
Map tile data did download.</p>
<p>Posted a bug on google code.</p>
<p>I&#8217;d like this to work&#8230;
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Iain</title>
		<link>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-18541</link>
		<pubDate>Mon, 07 Apr 2008 16:11:01 +0000</pubDate>
		<guid>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-18541</guid>
					<description>Just downloaded from svn today, April 7th 2008.  Having the same problem as others with the tiles not loading.  Do you have any ETA for the update?  I would love to be able to give this a try!</description>
		<content:encoded><![CDATA[<p>Just downloaded from svn today, April 7th 2008.  Having the same problem as others with the tiles not loading.  Do you have any ETA for the update?  I would love to be able to give this a try!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jake</title>
		<link>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-17168</link>
		<pubDate>Thu, 21 Feb 2008 21:41:54 +0000</pubDate>
		<guid>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-17168</guid>
					<description>Derek,
I'm very interested in your fix if you come by one. Thanks for putting together such a slick program; here's hoping it works out!


P.S. Any chance for Windows binaries? Pretty please?</description>
		<content:encoded><![CDATA[<p>Derek,<br />
I&#8217;m very interested in your fix if you come by one. Thanks for putting together such a slick program; here&#8217;s hoping it works out!</p>
<p>P.S. Any chance for Windows binaries? Pretty please?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: derek</title>
		<link>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-17164</link>
		<pubDate>Thu, 21 Feb 2008 14:50:07 +0000</pubDate>
		<guid>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-17164</guid>
					<description>hmm....yeah, looks like one of their updates broke ogmaps.  will try to figure out a fix this weekend.</description>
		<content:encoded><![CDATA[<p>hmm&#8230;.yeah, looks like one of their updates broke ogmaps.  will try to figure out a fix this weekend.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: egiron</title>
		<link>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-16927</link>
		<pubDate>Thu, 14 Feb 2008 20:02:56 +0000</pubDate>
		<guid>http://kered.org/blog/2007-12-02/take-google-maps-offline/#comment-16927</guid>
					<description>I did the same but I got a gray "Loading page" too, the mapfiles and tiles didn't load. It seems your program does not replace correctly the urls or something like that because it try to connect to google.</description>
		<content:encoded><![CDATA[<p>I did the same but I got a gray &#8220;Loading page&#8221; too, the mapfiles and tiles didn&#8217;t load. It seems your program does not replace correctly the urls or something like that because it try to connect to google.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
