
288
|
Chapter 5, Mapping with Gadgets
#63 Build Your Own Car Navigation System with GpsDrive
HACK
self.map.zoom_in( )
self.draw_map( )
def draw_map(self):
"""Remove all drawing objects from the Tk canvas, and re-draw them
with new coordinates"""
# delete old drawing items
self.canvas.delete("all")
# show the current viewing position and zoom
self.canvas.create_text(10,10,text="Location Lat=%f Lon=%f Zoom=%f"
% (self.map.lat, self.map.lon, self.map.zoom), anchor="nw")
self.wpt.draw(self.map, self.canvas)
self.track.draw(self.map, self.canvas)
# place a crosshair in the middle of the screen
self.canvas.create_line(self.width/2-5, self.height/2, self.width
/2+5, self.height/2)
self.canvas.create_line(self.width/2, self.height/2-5, self.width/2,
self.height/2+5)
self.canvas.pack( )
from Tkinter import *
root = Tk( )
app = App(root)
root.mainloop( )
Since this application only displays data stored in a file, it does not take
advantage of a mobile computer with a live GPS feed. In order to display live
updates, the previous code would need an additional thread to populate
new data into the GUI. If you are interested in adding this functionality, see
http://www.mappinghacks.com/projects/carcomputer and the next hack,
“Build Your Own Car Navigation System with GpsDrive”
[Hack #63].
—Thomas Hargrove
HACK
#63
Build Your Own Car Navigation System with
GpsDrive Hack #63
Watch your position on a map move as you move. ...