# # License : GPL # http://www.gnu.org/copyleft/gpl.html # (c) Mike Rowehl 2006 # miker@bitsplitter.net # # A Yahoo maps client for Nokia Series 60 phones. This one reads a single time # from the GPS till it gets a decent lock, and then requests a tile URL from # Yahoo and downloads the tile image. # import appuifw import urllib import e32 import socket import time class App: def __init__(self): self.displayUrl = None self.url = None self.optionList = ({'start':u'Start'},{'exit':u'Exit'}) self.lock = e32.Ao_lock() self.old_exit_key = appuifw.app.exit_key_handler appuifw.app.exit_key_handler = self.exit_handler self.running = 1 self.current_tab = 0 appuifw.app.set_tabs([u'Yahoo Maps GPS'], self.display_tab) self.display_tab(0) self.lock.wait() def exit_handler(self): self.running = 0 self.lock.signal() def display_tab(self, id): appuifw.app.body = appuifw.Listbox(self.optionList[id].values(), self.load) self.current_tab = id def getImage(self, lat, long): tempfile = "C:\\s60_py_gpsmap_api_cache" url = "http://api.local.yahoo.com/MapsService/V1/mapImage?appid=s60_py_gpsmap&latitude=%s&longitude=%s&image_height=145&image_width=176&zoom=3" % (lat,long) self.url = url urllib.urlretrieve( url, tempfile ) f = open( tempfile, 'r' ) mapinfo = f.read() f.close() startrestag = mapinfo.find( '', startrestag ) endrestag = endrestag + 1 endrestext = mapinfo.find( '<', endrestag ) imgurl = mapinfo[endrestag:endrestext] urllib.urlretrieve(imgurl, "C:\\ymap.png") def load(self): haveFix=0 latitude_in=0 longitude_in=0 self.sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM) address,services=socket.bt_discover() target=(address,services.values()[0]) self.sock.connect(target) while self.running: buffer="" ch=self.sock.recv(1) while(ch!='$'): ch=self.sock.recv(1) while 1: if (ch=='\r'): break buffer+=ch ch=self.sock.recv(1) if (buffer[0:6]=="$GPGGA"): try: (GPGGA,utcTime,lat,ns,lon,ew,posfix,sats,hdop,alt,altunits,sep,sepunits,age,sid)=buffer.split(",") latitude_in=float(lat) longitude_in=float(lon) haveFix=int(posfix) except: haveFix=0 if haveFix: zoom=2 if ns == 'S': latitude_in = -latitude_in if ew == 'W': longitude_in = -longitude_in latitude_degrees = int(latitude_in/100) latitude_minutes = latitude_in - latitude_degrees*100 longitude_degrees = int(longitude_in/100) longitude_minutes = longitude_in - longitude_degrees*100 latitude = latitude_degrees + (latitude_minutes/60) longitude = longitude_degrees + (longitude_minutes/60) self.getImage( latitude, longitude ) if self.url!=self.displayUrl: try: id = appuifw.app.body.current() content_handler = appuifw.Content_handler() content_handler.open("C:\\ymap.png") except IOError: appuifw.note(u"Could not fetch the map.",'info') except Exception, E: appuifw.note(u"Could not open the map, %s"%E,'info') self.displayUrl = self.url self.running = 0 time.sleep(0.2) A = App()