
livegps.py
By: a guest on Dec 11th, 2010 | syntax:
Python | size: 1.54 KB | hits: 298 | expires: Never
'''
Started on 10, Dec 2010 by Maxin B. John <maxinbjohn@gmail.com>
This file is licensed under the GPLv3
'''
import android
import urllib2
import time
import string
droid = android.Android()
def get_update_gps_status():
''' GET and Update the GPS status in Server'''
# PHP script expects the longitude and latitude in the URL as given below
GPS_URL='http://www.maxinbjohn.info/locate-mii/test.php?lat=%s&long=%s'
# begins the gps location process in Phone
droid.startLocating()
# giving some time for the phone to think :)
time.sleep(10)
try:
# read the latitude and longitude from the phone
loc= droid.readLocation()[1]
# check for Null in pythonic way
if loc:
longitude = loc['network']['longitude']
latitude = loc['network']['latitude']
# prepares the URL as expected by the PHP script
url = GPS_URL % (latitude, longitude)
print url
try:
# submits the latitude and longitude values to the web page
handler = urllib2.urlopen(url)
# to ensure the data submission
data = handler.read()
except URLError:
print "Error in Connection!"
finally:
handler.close()
except:
print "Error in getting the lattitde and longitude values!"
if __name__ == '__main__':
''' Updating the GPS status in Server '''
while True:
get_update_gps_status()