-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgps.py
42 lines (33 loc) · 1.04 KB
/
gps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import android, time, string
latitude = None
longitude = None
failed = True
def get_location(droid):
print 'Finding location'
droid.startLocating(5000)
time.sleep(10)
while 1:
failed = True;
location = droid.readLocation().result
if location == {}:
print "Current location unknown"
location = droid.getLasKnownLocation().result
if location != {}:
if location['gps'] != None:
print 'GPS: '
latitude = location['gps']['latitude']
longitude = location['gps']['longitude']
failed = False
elif location['network'] != {}:
print 'Network: '
latitude = location['network']['latitude']
longitute = location['network']['longitude']
failed = False
if not failed:
print 'Latitude: ' + str(latitude) + ' Longitude: ' + str(longitude) +'\n'
else:
print 'Failed to get location'
time.sleep(5)
if __name__ == '__main__':
droid = android.Android()
get_location(droid)