×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Regular Contributor
    Join Date
    Jan 2005
    Location
    Bangkok, Thailand
    Posts
    148

    Google Map on pys60

    Here's a prototype. It let you move around (using cursor).
    Zoom in using 'select', Zoom out using star. This example
    demonstrates how to tile the 256x256 images to fill the screen.

    First, I download some of these images, so I don't need to use
    GPRS. A few of them around Sanfran. at different zoom levels.
    The download code is something like this
    Code:
    from urllib import urlretrieve
    turl =  'http://mt.google.com/mt?v=w2.4&x=%s&y=%s&zoom=%s'
    tfile = '%s-%s-%s.gif'
    z = 12
    for x in range(5,10):
      for y in range(10,14):
        urlretrieve(turl % (x,y,z), tfile % (z,y,x))
    Notice that to zoom it by hand you double the x and y, decriment z.
    For example
    x = 20, y = 49, z = 10
    When you zoom in, you get double precision (split into 4 images)
    The top left is 40, 98, 9. The buttom right is 41,99,9

    Now come the tiling code.
    Notice that I use x,y as the top-left corner of the screen.
    This should make the code a bit simpler. (I think).
    Last edited by korakotc; 2005-07-04 at 19:38.

  2. #2
    Regular Contributor
    Join Date
    Jan 2005
    Location
    Bangkok, Thailand
    Posts
    148
    Code:
    from appuifw import *
    from key_codes import *
    from graphics import Image
    import e32
    
    app.screen = 'full'
    app.body = c= Canvas()
    
    x, y, z = 10*256, 24*256, 11
    dirname = u'C:\\system\\data\\gmap\\\'  # where I save the tile images
    
    def draw():
        gx, ox = divmod(x, 256)
        gy, oy = divmod(y, 256)
        f = dirname + '%s-%s-%s.gif' % (z,gy,gx)
        c.blit(Image.open(f), target=(-ox,-oy, 256-ox,256-oy))
    
        if ox > 80:
            f = dirname + '%s-%s-%s.gif' % (z,gy,gx+1)
            c.blit(Image.open(f), target=(256-ox,-oy, 512-ox,256-oy))
        if oy > 48:
            f = dirname + '%s-%s-%s.gif' % (z,gy+1,gx)
            c.blit(Image.open(f), target=(-ox,256-oy, 256-ox,512-oy))
        if ox > 80 and oy > 48:
            f = dirname + '%s-%s-%s.gif' % (z,gy+1,gx+1)
            c.blit(Image.open(f), target=(256-ox,256-oy, 512-ox,512-oy))
    
    def move(dx,dy):
        global x, y
        x += dx * 50
        y += dy * 50
        draw()
    
    def zoomin():
        global x,y,z
        x = x*2 + 88
        y = y*2 + 104
        z = z-1
        draw()
    
    def zoomout():
        global x,y,z
        x = x/2 - 44
        y = y/2 - 52
        z = z+1
        draw()
    
    c.bind(EKeyRightArrow,lambda:move(1, 0))
    c.bind(EKeyLeftArrow,lambda:move(-1, 0))
    c.bind(EKeyUpArrow,lambda:move(0, -1))
    c.bind(EKeyDownArrow,lambda:move(0, 1))
    c.bind(EKeySelect, zoomin)
    c.bind(EKeyStar, zoomout)
    
    running = 1
    def quit():
        global running
        running = 0
    app.exit_key_handler= quit
    
    draw()
    while running:
        e32.ao_sleep(0.1)
    To make it runing online, you can write code to retrieve and
    cache the images. (Wouldn't be difficult, right?)
    Last edited by korakotc; 2005-07-04 at 19:36.

  3. #3
    Regular Contributor
    Join Date
    Jan 2005
    Location
    Bangkok, Thailand
    Posts
    148
    It seems not many people are interested to try out.
    So, I have modify the code a bit. Now it will retrieve
    the tile images directly from google.
    It doesn't cache the files across session yet.
    (need 3 more lines, but I love simple codes)

    Please have a look if it works for you.
    Code:
    # s60_gmap version 0.2
    from appuifw import *
    from key_codes import *
    from graphics import Image
    from urllib import urlretrieve
    import e32
    
    app.screen = 'full'
    app.body = c= Canvas()
    
    x, y, z = 10*256, 24*256, 11
    cache = {}
    
    def draw():
        gx, ox = divmod(x, 256)
        gy, oy = divmod(y, 256)
        tile(gx, gy, -ox, -oy)  # top-left tile and 3 optional tiles
        if ox > 80:
            tile(gx+1, gy, 256-ox, -oy)
        if oy > 48:
            tile(gx, gy+1, -ox, 256-oy)
        if ox > 80 and oy > 48:
            tile(gx+1, gy+1, 256-ox, 256-oy)
    
    def tile(tx, ty, left, top):
        t = (tx, ty, z)
        rect = (left, top, left+256, top+256)
        if t in cache:
            im = cache[t]
        else:
            f = u'C:\\tile.gif'
            c.rectangle(rect, fill=0xffffff)
            c.text((left+5, top+20), u'Loading')
            urlretrieve('http://mt.google.com/mt?v=w2.5&x=%s&y=%s&zoom=%s' % t, f)
            cache[t] = im = Image.open(f)
        c.blit(im, target=rect)
    
    
    def move(dx,dy):
        global x, y
        x += dx * 50
        y += dy * 50
        draw()
    
    def zoomin():
        global x,y,z
        x = x*2 + 88
        y = y*2 + 104
        z = z-1
        draw()
    
    def zoomout():
        global x,y,z
        x = x/2 - 44
        y = y/2 - 52
        z = z+1
        draw()
    
    c.bind(EKeyRightArrow,lambda:move(1, 0))
    c.bind(EKeyLeftArrow,lambda:move(-1, 0))
    c.bind(EKeyUpArrow,lambda:move(0, -1))
    c.bind(EKeyDownArrow,lambda:move(0, 1))
    c.bind(EKeySelect, zoomin)
    c.bind(EKeyStar, zoomout)
    
    running = 1
    def quit():
        global running
        running = 0
    app.exit_key_handler= quit
    
    draw()
    while running:
        e32.ao_sleep(0.1)
    Last edited by korakotc; 2005-07-30 at 09:32.

  4. #4
    Regular Contributor
    Join Date
    Oct 2004
    Posts
    158
    Great app! Unfortunately it crashes on:

    - 6630
    - Python 1.1.6 fast

    One tile of the map is loaded correctly, but when I'm scrolling in a certain direction Python complete disappears without any notice.

    It might work with the non-fast version since the fast version is pretty instable.

    About the lack of responses: yep, I noticed that as well. I would expect a little more interest in such a cool technology. On the other hand, it might be because half of Europe is on holiday.

  5. #5
    Regular Contributor
    Join Date
    Jan 2005
    Location
    Bangkok, Thailand
    Posts
    148
    It's not very responsive and crash on mine as well.
    - 6600
    - pys60 1.1.6 fast

    I suspect it is because urlretrieve is running when I move
    the cursor and the draw command (and urlretrieve) is called
    again. So, the 2 urlretrieve is interfering each other.
    When I wait for all 4 tiles to complete, it doesn't crash.

    I will try to change a few lines to make it work better
    (probably add url-caching as well)
    Please help look at what is the real cause of the bug.

  6. #6
    Regular Contributor
    Join Date
    Jan 2005
    Location
    Bangkok, Thailand
    Posts
    148
    Here's the 0.3 version.
    It does url caching, which improve responsiveness considerably.
    For places you have visited, you don't need to connect to GPRS.
    I may add satellite images in the next version.
    Any feature request?
    Code:
    # s60_gmap version 0.3
    from appuifw import *
    from key_codes import *
    from graphics import Image
    from os.path import exists
    from urllib import urlretrieve
    import e32
    
    app.screen = 'full'
    app.body = c= Canvas()
    
    fmt_url = 'http://mt.google.com/mt?v=w2.5&x=%s&y=%s&zoom=%s'
    fmt_file = u'E:\\system\\data\\%s-%s-%s.png' # memcard has more space
    x, y, z = 10*256, 24*256, 11
    cache = {}
    
    def draw():
        gx, ox = divmod(x, 256)
        gy, oy = divmod(y, 256)
        tile(gx, gy, -ox, -oy)  # top-left tile and 3 optional tiles
        if ox > 80:
            tile(gx+1, gy, 256-ox, -oy)
        if oy > 48:
            tile(gx, gy+1, -ox, 256-oy)
        if ox > 80 and oy > 48:
            tile(gx+1, gy+1, 256-ox, 256-oy)
    
    def tile(tx, ty, left, top):
        t = (tx, ty, z)
        rect = (left, top, left+256, top+256)
        # here we use 2 level cache
        if t in cache:
            im = cache[t]
        else:
            f = fmt_file % t
            if not exists(f):
                c.rectangle(rect, fill=0xffffff)
                c.text((left+5, top+20), u'Loading')
                urlretrieve(fmt_url%t, f)   # url cache
            cache[t] = im = Image.open(f)   # object cache
        c.blit(im, target=rect)
    
    def move(dx,dy):
        global x, y
        x += dx * 50
        y += dy * 50
        draw()
    
    def zoomin():
        global x,y,z
        x = x*2 + 88
        y = y*2 + 104
        z = z-1
        draw()
    
    def zoomout():
        global x,y,z
        x = x/2 - 44
        y = y/2 - 52
        z = z+1
        draw()
    
    
    c.bind(EKeyRightArrow,lambda:move(1, 0))
    c.bind(EKeyLeftArrow,lambda:move(-1, 0))
    c.bind(EKeyUpArrow,lambda:move(0, -1))
    c.bind(EKeyDownArrow,lambda:move(0, 1))
    c.bind(EKeySelect, zoomin)
    c.bind(EKeyStar, zoomout)
    
    running = 1
    def quit():
        global running
        running = 0
    app.exit_key_handler= quit
    
    draw()
    while running:
        e32.ao_sleep(0.1)
    Last edited by korakotc; 2005-07-31 at 08:30.

  7. #7
    Regular Contributor
    Join Date
    Jan 2005
    Location
    Bangkok, Thailand
    Posts
    148
    Here's a 0.4 version that display satellite map using 'hash' key to
    toggle between 'map' and 'sat' mode
    Code:
    # s60_gmap version 0.4
    from appuifw import *
    from key_codes import *
    from graphics import Image
    from os.path import exists
    from urllib import urlretrieve
    import e32
    
    app.screen = 'full'
    app.body = c= Canvas()
    
    fmt_file = u'E:\\system\\data\\%s-%s-%s' # memcard has more space
    x, y, z = 10*256, 24*256, 11
    mode = 'map'
    cache = {'map': {}, 'sat': {} }
    ext = {'map':'.png', 'sat':'.jpg'}
    
    def draw():
        gx, ox = divmod(x, 256)
        gy, oy = divmod(y, 256)
        tile(gx, gy, -ox, -oy)  # top-left tile and 3 optional tiles
        if ox > 80:
            tile(gx+1, gy, 256-ox, -oy)
        if oy > 48:
            tile(gx, gy+1, -ox, 256-oy)
        if ox > 80 and oy > 48:
            tile(gx+1, gy+1, 256-ox, 256-oy)
    
    def tile(tx, ty, left, top):
        t = (tx, ty, z)
        rect = (left, top, left+256, top+256)
        # here we use 2 level cache
        if t in cache[mode]:
            im = cache[mode][t]
        else:
            f = fmt_file % t + ext[mode]
            if not exists(f):
                c.rectangle(rect, fill=0xffffff)
                c.text((left+5, top+20), u'Loading')
                urlretrieve(tile_url(t), f)   # url cache
            cache[mode][t] = im = Image.open(f)   # object cache
        c.blit(im, target=rect)
    
    def tile_url(t):
        if mode=='map':
            return 'http://mt.google.com/mt?v=w2.5&x=%s&y=%s&zoom=%s' % t
        quadtree = []  # calculate satellite quadtree url
        m = {(0,0):'q', (0,1):'t', (1,0):'r', (1,1):'s'}
        _x, _y, z = t
        for i in range(17-z):
            _x, rx = divmod(_x, 2)
            _y, ry = divmod(_y, 2)
            quadtree.insert(0, m[(rx,ry)])
        return 'http://kh.google.com/kh?v=3&t=t' + ''.join(quadtree)
    
    def move(dx,dy):
        global x, y
        x += dx * 50
        y += dy * 50
        draw()
    
    def zoomin():
        global x,y,z
        x = x*2 + 88
        y = y*2 + 104
        z = z-1
        draw()
    
    def zoomout():
        global x,y,z
        x = x/2 - 44
        y = y/2 - 52
        z = z+1
        draw()
    
    def toggle_mode():
        global mode
        if mode == 'map':
            mode = 'sat'
        else:
            mode = 'map'
        draw()
    
    c.bind(EKeyRightArrow,lambda:move(1, 0))
    c.bind(EKeyLeftArrow,lambda:move(-1, 0))
    c.bind(EKeyUpArrow,lambda:move(0, -1))
    c.bind(EKeyDownArrow,lambda:move(0, 1))
    c.bind(EKeySelect, zoomin)
    c.bind(EKeyStar, zoomout)
    c.bind(EKeyHash, toggle_mode)
    
    running = 1
    def quit():
        global running
        running = 0
    app.exit_key_handler= quit
    
    draw()
    while running:
        e32.ao_sleep(0.1)
    Now the code become exactly 100 lines.

  8. #8
    Regular Contributor
    Join Date
    Oct 2004
    Posts
    158
    - 6630
    - Python 1.1.6 fast

    Version 0.4 sometimes crashes on

    1. line 42 on:

    Code:
    urlretrieve(tile_url(t), f)
    It leads to an error in line 57 in Graphics.py. The SymbianError is [Errno -10]

    2. For the rest: you hardcoded a file on the memorycard. You can't assume a card to be present (as on my phone), if it's not, the app will crash.

    3. Sometimes the app just completely crashes while scrolling, but that might be due to the same error we discussed before (no multithreaded downloading of images).


    Anyway, the app is getting pretty cool. Would you be so kind to comment the source a little more? Especially the code with regards to calculating the coordinates needed for Google Maps are hard to decypher without prior knowledge.

  9. #9
    Regular Contributor
    Join Date
    Jan 2005
    Location
    Bangkok, Thailand
    Posts
    148
    I will probably correct the problem in the next version. Tile displaying and retrieval will be done separately to avoid interfering between to two urlretrieves.

    For now, a screenshot for those who like to see before you try.
    http://flickr.com/photos/korakot/30189624/

  10. #10
    Registered User
    Join Date
    Jul 2004
    Posts
    2

    good stuff

    I Think there is interest in this - but Nokia forums are not always the most popular hang-outs for the avant garde kids!

    Is there any way you can integrate a search box into this?

    Screenshots look great, will try it more properly once I get GPRS plan.

  11. #11
    Registered User
    Join Date
    Sep 2005
    Posts
    2

    Re: Google Map on pys60

    sounds very cool, but does not run on my SX1 with alpha 1.1.6 for 1st ED
    get following error:
    line 41, in tile cache[mode][t] = im = Image.open(f)
    AttributeError: type object 'Image' has no attribute 'open'

    unfortunatley i'm not a programmer and have no idea what to do to correct this issue. Mayby some one can help??
    Thanks

  12. #12
    Regular Contributor
    Join Date
    Jan 2005
    Location
    Bangkok, Thailand
    Posts
    148

    Re: Google Map on pys60

    The problem is 1st ED phone (3650, SX1) doesn't support Image.open().

    A solution is given in this thread
    http://discussion.forum.nokia.com/fo...ad.php?t=65720
    However, you need to compile the code yourself (available only in source).
    Setting up an environment for compiling may not be easy for you (nor for me).

  13. #13
    Registered User
    Join Date
    Sep 2005
    Posts
    2

    Re: Google Map on pys60

    Thanks for the quick help!!! and the link!!!
    it is not the first time i run into trouble with my 1st ed symbian phone. I wait for my new one which is a second ed, because as you pointed out correctly, fixing this is beyond my scope.
    Anyway, i think combining google maps with symbian and python is the future. so keep up the good work. the future will be geotagged and mobile!
    Tom

  14. #14
    Registered User
    Join Date
    Oct 2005
    Posts
    19

    Re: Google Map on pys60

    Hello

    Can this be made using Java? It'll be quite interesting...if anybofy had try or will, please send me an e-mail to kimi007@gmail.com

    Thanks
    Ezequiel

  15. #15
    Regular Contributor
    Join Date
    May 2006
    Posts
    74

    Re: Google Map on pys60

    This is a really good idea! And really shows you just how easy it is to make a powerful application in Python, but I think the lack of interest may come from the fact that Google have already made a mobile version of Google Maps, both in Java and in Symbian C++ (I assume it's C++ anyway).

    I've been using it for a while and it works quite nicely!
    http://www.google.com/gmm/index.html
    chetbox.googlepages.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×