DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Using Google Map On Mobile Phone

07.04.2005
| 10364 views |
  • submit to reddit
        Download the tile images for testing
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))
Then put the images in the phone. Then use the following code
to browse around the images (and zoom in/out)
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))

    if ox > 80:
        f = dirname + '%s-%s-%s.gif' % (z,gy,gx+1)
        c.blit(Image.open(f), target=(256-ox,-oy))
    if oy > 48:
        f = dirname + '%s-%s-%s.gif' % (z,gy+1,gx)
        c.blit(Image.open(f), target=(-ox,256-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))

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)
I put a bit more explanation in Nokia's forum here. (Newer version is available)
http://discussion.forum.nokia.com/forum/showthread.php?s=&postid=153609
Also see the screenshot here
http://flickr.com/photos/korakot/30189624/    

Comments

Snippets Manager replied on Fri, 2009/10/02 - 9:46am

Mobile GMaps is a FREE application that displays maps from Google Maps, Yahoo! ... Ask.com, Open Street Map and other sources on Java J2ME-enabled mobile phones, ... and all searches are performed using Google Maps search features. joinery

Snippets Manager replied on Fri, 2009/10/02 - 9:46am

Mobile GMaps is a FREE application that displays maps from Google Maps, Yahoo! ... Ask.com, Open Street Map and other sources on Java J2ME-enabled mobile phones, ... and all searches are performed using Google Maps search features. email to sms