Hi I am testing my below program on my Android Moto E4. It does not seem to get a GPS Fix even when I am outside waiting for an 30 mins can anybody please guide me where I am going wrong. Below is my code using Qpython 3.6 and Qpythong 2.7 Android app. The main goal of this program is to get a GPS fix and enter the logs in the file which is stored in the phone at a particular location . I also tested but seems to be giving some errors.
import androidhelper, os, time, datetime
droid = androidhelper.Android()
droid.startLocating()
while not droid.readLocation()[1].has_key('gps') :
print "Waiting on gps to turn on"
time.sleep(15)
if not os.path.exists('/sdcard/logs'):
os.mkdir('/sdcard/logs')
# Now we'll loop until the user closes the application
while True:
loc = droid.readLocation()
lat = str(loc.result['gps']['latitude'])
lon = str(loc.result['gps']['longitude'])
alt = str(loc.result['gps']['altitude'])
now = str(datetime.datetime.now())
f = open('/sdcard/logs/logfile.txt','a')
outString = now + ',' + lat + ',' + lon + ',' + alt + '\n'
f.write(outString)
print outString
f.close()
time.sleep(15)