So I have made this piece of code to get values of GPS location, date and time. And then I will try to make them in a JSON and send them through Wi-Fi to a server. Anyway, the problem is it always reads previous location values. It always reads the values from the "Network" part of the JSON provided by the previous values. The current location, printed is only two brackets "{ }" as you can see if you run the code.
The GPS icon on the phone does not activate when I run the script directly from the phone. I guess the code is self explanatory but if there are any questions please ask.
import android,time,datetime
droid = android.Android()
latitudine = "initial value"
longitudine = "initial value"
indexVal = 1
lostSignal = False
while True:
print "~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~\nNew reading: #" + str(indexVal) +"\n"
droid.startLocating()
locatie = droid.readLocation().result
droid.stopLocating()
print "Reading result: " + str(locatie)
if locatie == {}:
print "Current location information not available"
locatie=droid.getLastKnownLocation().result
if locatie != {}:
if locatie['gps'] == None:
if locatie['network'] == {}:
latitudine = str(locatie['passive']['latitude'])
longitudine = str(locatie['passive']['longitude'])
print "Reading passive data (from last known location):"
print longitudine
print latitudine
lostSignal = True
elif locatie['network'] != {}:
latitudine = str(locatie['network']['latitude'])
longitudine = str(locatie['network']['longitude'])
print "Reading data from network:"
print latitudine
print longitudine
lostSignal = True
elif locatie['gps']!=None:
if lostSignal == True:
droid.vibrate(500)
lostSignal = False
latitudine=str(locatie['gps']['latitude'])
longitudine=str(locatie['gps']['longitude'])
print "Reading data from GPS:"
print latitudine
print longitudine
droid.notify("GPS found","GPS signal found.\nData aquired")
print "\nFull available information:\n"
for locInfo in locatie.iteritems():
print str(locInfo)
print "\n"
now = datetime.datetime.now()
ora = now.hour
minut = now.minute
secunda = now.second
ziua = now.day
luna = now.month
an = now.year
print str(ora)+":"+str(minut)+":"+str(secunda)+" / "+str(ziua)+"-"+str(luna)+"-"+str(an)
indexVal += 1
time.sleep(20)