You Are Here:

Community: Developer Discussion Boards

Reply « Previous Thread | Next Thread »

#1 Old Google Map on pys60 - 2005-07-04, 20:22

Join Date: Jan 2005
Posts: 148
Location: Bangkok, Thailand
Send a message via MSN to korakotc
korakotc's Avatar
korakotc
Offline
Regular Contributor
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 20:38.
Reply With Quote

#2 Old 2005-07-04, 20:24

Join Date: Jan 2005
Posts: 148
Location: Bangkok, Thailand
Send a message via MSN to korakotc
korakotc's Avatar
korakotc
Offline
Regular Contributor
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 20:36.
Reply With Quote

#3 Old 2005-07-30, 10:06

Join Date: Jan 2005
Posts: 148
Location: Bangkok, Thailand
Send a message via MSN to korakotc
korakotc's Avatar
korakotc
Offline
Regular Contributor
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 10:32.
Reply With Quote

#4 Old 2005-07-30, 21:28

Join Date: Oct 2004
Posts: 158
bercobeute
Offline
Regular Contributor
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.
Reply With Quote

#5 Old 2005-07-31, 03:36

Join Date: Jan 2005
Posts: 148
Location: Bangkok, Thailand
Send a message via MSN to korakotc
korakotc's Avatar
korakotc
Offline
Regular Contributor
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.
Reply With Quote

#6 Old 2005-07-31, 09:17

Join Date: Jan 2005
Posts: 148
Location: Bangkok, Thailand
Send a message via MSN to korakotc
korakotc's Avatar
korakotc
Offline
Regular Contributor
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 09:30.
Reply With Quote

#7 Old 2005-07-31, 10:41

Join Date: Jan 2005
Posts: 148
Location: Bangkok, Thailand
Send a message via MSN to korakotc
korakotc's Avatar
korakotc
Offline
Regular Contributor
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.
Reply With Quote

#8 Old 2005-07-31, 20:18

Join Date: Oct 2004
Posts: 158
bercobeute
Offline
Regular Contributor
- 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.
Reply With Quote

#9 Old 2005-08-03, 18:17

Join Date: Jan 2005
Posts: 148
Location: Bangkok, Thailand
Send a message via MSN to korakotc
korakotc's Avatar
korakotc
Offline
Regular Contributor
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/
Reply With Quote

#10 Old good stuff - 2005-08-10, 01:04

Join Date: Jul 2004
Posts: 2
nokiaaa3
Offline
Registered User
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.
Reply With Quote

#11 Old Re: Google Map on pys60 - 2005-09-16, 22:31

Join Date: Sep 2005
Posts: 2
tom.coupland
Offline
Registered User
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
Reply With Quote

#12 Old Re: Google Map on pys60 - 2005-09-17, 00:01

Join Date: Jan 2005
Posts: 148
Location: Bangkok, Thailand
Send a message via MSN to korakotc
korakotc's Avatar
korakotc
Offline
Regular Contributor
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).
Reply With Quote

#13 Old Re: Google Map on pys60 - 2005-09-18, 19:32

Join Date: Sep 2005
Posts: 2
tom.coupland
Offline
Registered User
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
Reply With Quote

#14 Old Re: Google Map on pys60 - 2006-01-21, 13:14

Join Date: Oct 2005
Posts: 19
kimi007
Offline
Registered User
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
Reply With Quote

#15 Old Re: Google Map on pys60 - 2006-06-20, 12:34

Join Date: May 2006
Posts: 74
chetbox's Avatar
chetbox
Offline
Regular Contributor
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
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d121773X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ