-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlocation.repy
204 lines (135 loc) · 4.79 KB
/
location.repy
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
"""
<Program>
location.repy
Variables are mostly from:
http://www.mithril.com.au/android/doc/LocationFacade.html
<Date Started>
December 19th, 2013
<Author>
Yanyan Zhuang
<Purpose>
Trying to use the SL4A JSON bridge to read location info
"""
dy_import_module_symbols("sensorutil")
def location_providers(sl4a_socket):
"""
<Purpose>
Returns available providers on the phone.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
<Return>
{"error":null,"id":0,"result":["network","passive","gps"]}
"""
result = json_rpc(sl4a_socket, "locationProviders")
return result
def location_provider_enabled(sl4a_socket, provider):
"""
<Purpose>
Ask if provider is enabled
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
provider - (String) Name of location provider, such as network,
gps, or passive
<Return>
{"error":null,"id":0,"result":true}
"""
result = json_rpc(sl4a_socket, "locationProviderEnabled", provider)
return result
def location_start_locating(sl4a_socket, minDistance = 60000,
minUpdateDistance = 30):
"""
<Purpose>
Starts collecting location data.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
minDistance (Integer) minimum time between updates in
milliseconds (default=60000)
minUpdateDistance (Integer) minimum distance between
updates in meters (default=30)
<Return>
{"error":null,"id":0,"result":null}
"""
# ignoring the other two parameters for now
result = json_rpc(sl4a_socket, "startLocating")
return result
def location_read(sl4a_socket):
"""
<Purpose>
Returns the current location as indicated by all available
providers.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
<Return>
{"error":null,"id":0,"result":{"network":{"time":1386301597691,
"speed":0,"altitude":0,"bearing":0,"provider":"network",
"longitude":-123.2488612,"latitude":49.2611662,"accuracy":20}}}
"""
# ignoring the other two parameters for now
result = json_rpc(sl4a_socket, "readLocation")
return result
def location_get_last_known(sl4a_socket):
"""
<Purpose>
Returns the last known location of the device.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
<Return>
{"error":null,"id":0,"result":{
"passive":{"time":1386292156814,"speed":0,"altitude":0,
"bearing":0,"provider":"network",
"longitude":-123.2485678,"latitude":49.2610633,
"accuracy":36},
"gps":{"time":1386229651000,"speed":1.634053349494934,
"altitude":115,"bearing":235.37033081054688,
"provider":"gps","longitude":-123.24900053036713,
"latitude":49.26100681798307,"accuracy":40},
"network":{"time":1386292156814,"speed":0,"altitude":0,
"bearing":0,"provider":"network",
"longitude":-123.2485678,"latitude":49.2610633,
"accuracy":36}}}
"""
# ignoring the other two parameters for now
result = json_rpc(sl4a_socket, "getLastKnownLocation")
return result
def location_geocode(sl4a_socket, latitude, longitude, maxResults = 1):
"""
<Purpose>
Returns a list of addresses for the given latitude and longitude.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
latitude (Double)
longitude (Double)
maxResults (Integer) maximum number of results (default=1)
<Return>
{"error":null,"id":0,"result":[{"locality":"Vancouver",
"admin_area":"British Columbia","thoroughfare":"Main Mall",
"feature_name":"2366","country_code":"CA",
"country_name":"Canada","postal_code":"V6T 1Z4"}]}
"""
# ignoring the other two parameters for now
# sometimes returns Service not Available...
if maxResults != 1:
result = json_rpc(sl4a_socket, "geocode", latitude, longitude,
maxResults)
else:
result = json_rpc(sl4a_socket, "geocode", latitude, longitude)
return result
def location_stop_locating(sl4a_socket):
"""
<Purpose>
Stops collecting location data.
<Arguments>
sl4a_socket - the socket that has been established for
RPC communication
<Return>
{"error":null,"id":0,"result":null}
"""
# ignoring the other two parameters for now
result = json_rpc(sl4a_socket, "stopLocating")
return result