from gps import *
import time
import threading
import math
import webiopi ######
class GpsController(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info
self.running = False
def run(self):
self.running = True
while self.running:
# grab EACH set of gpsd info to clear the buffer
self.gpsd.next()
def stopController(self):
self.running = False
@property
def fix(self):
return self.gpsd.fix
def loop(): #####
# create the controller
gpsc = GpsController()
try:
# start controller
gpsc.start()
while True:
print "latitude ", gpsc.fix.latitude
print "longitude ", gpsc.fix.longitude
time.sleep(0.5)
#Error
except:
print "Unexpected error:", sys.exc_info()[0]
raise
#Ctrl C
except KeyboardInterrupt:
print "User cancelled"
finally:
print "Stopping gps controller"
gpsc.stopController()
#wait for the tread to finish
gpsc.join()
print "Done"
@webiopi.macro
def read_latitude():
gpsc = GpsController()
return "latitude ", gpsc.fix.latitude
@webiopi.macro
def read_longitude():
gpsc = GpsController()
return "longitude ", gpsc.fix.longitude
Ruben
"latitude", gpsc.fix.latitude
Ruben
Now in the index.html, it theres any way to use that global variable?
var position = new google.maps.LatLng(x, y);