-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathlocationsensor.html
More file actions
233 lines (233 loc) · 8.08 KB
/
Copy pathlocationsensor.html
File metadata and controls
233 lines (233 loc) · 8.08 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta content="App Inventor for Android" name="description" />
<meta content="Android, Blocks App Inventor, Mobile, Phone, IDE" name="keywords" />
<title>
Display Lists - App Inventor for Android
</title>
<link href="/static/images/appinventor-16.png" rel="SHORTCUT ICON" type="image/ico" />
<link href="/static/images/appinventor-16.png" rel="icon" type="image/png" />
<link href="/static/css/appinventor.css" rel="stylesheet" />
<script src="http://www.google.com/js/gweb/analytics/autotrack.js">
</script>
<script>
var tracker = new gweb.analytics.AutoTrack({
profile: 'UA-5856106-2'
});
</script>
<script language = "JavaScript" src="/static/scripts/HeaderAndFooter.js"></script>
<style>
img.c2 {border-width:0}
div.c1 {clear:both;}
</style>
</head>
<body>
<script language = "JavaScript">createHeader('<div id="navigation-breadcrumb"> <a href="/learn/">Learn</a> > <a href="/learn/reference">Reference</a> > Using the Location Sensor > ');</script><br>
<div id="aiac">
<div class="main-container">
<div class="customhr customhr-gray">
</div>
<div class="content">
<div class="content-body">
<div class="learn-page">
<h1>
Using the Location Sensor
</h1>
<p>
The LocationSensor component can determine the phone's latitude and longitude as
well as a street address. You can use it to share your location with others, record
"breadcrumbs" on a journey or treasure hunt, or as a way to take roll in class (as
long as the students have Android devices!)
</p>
<p>
The sample apps below are simple but illustrate the basic way that location can be
determined. Both apps report the current latitude, longitude, and addres on the
phone's display and, just for fun, speak the address aloud. The first app reports
the location as soon as the sensor gets the data and every time the phone's
location is changed. The second app only invokes the location sensor in response to
an event-- when the user clicks a button.
</p>
<p>
For each sample app, the following is provided:
</p>
<ul>
<li>
A barcode which can be scanned to
<strong>
install
</strong>
the app on your
phone.
</li>
<li>
The source code (blocks) for you to use/
<strong>
customize
</strong>
. Download
the file to your computer then upload it into App Inventor.
</li>
<li>
A snapshot of the app in the Component
<strong>
Designer
</strong>
</li>
<li>
<strong>
Annotated blocks
</strong>
to help you understand the app. The annotations
are block comments that will appear in the app when you upload it as well.
</li>
</ul>
<h2>
Sample App 1: Location Reader
</h2>
<p>
Report location data as soon as sensor reads it and when the location changes
</p>
<table border="0">
<tr>
<td>
<strong>
TRY IT!
</strong>
Scan the QR code with your Android phone to install
this app (if you haven't already, download a scanner from the Android Market)
</td>
<td>
<img alt="" height="179" src="LocationSensorAssets/locationBarcode.png" width="214" />
</td>
</tr>
<tr>
<td>
<strong>
CUSTOMIZE IT!
</strong>
. Download the source blocks to your phone by
clicking the button on the right, then upload into App Inventor by choosing
More Actions | Upload Source on the Projects page.
</td>
<td>
<a href="LocationSensorAssets/LocationTest.zip">
<img alt="" height="116" src="LocationSensorAssets/customize.png" width="211" />
</a>
</td>
</tr>
</table>
<strong>
UNDERSTAND IT!
</strong>
Here is the user interface and components for
the app:
<div class="imagecontainer">
<img alt="" height="587" src="LocationSensorAssets/designer.png" width="724" />
</div>
<p>
Here are the blocks for the app, with annotation:
</p>
<div class="imagecontainer">
<img alt="" height="520" src="LocationSensorAssets/locationChangedBlocks.png" width="720" />
</div>
<h2>
Sample App 2: Get the location when a button is clicked
</h2>
<p>
This app illustrates how to access location information only when some event
occurs. The LocationSensor is disabled to begin, then enabled when the button is
clicked and disabled once again when the location is determined.
</p>
<table border="0">
<tr>
<td>
<strong>
TRY IT!
</strong>
Scan the QR code with your Android phone to install
this app (if you haven't already, download a scanner from the Android Market)
</td>
<td>
<img alt="" src="LocationSensorAssets/locationOnclickBarcode.png" />
</td>
</tr>
<tr>
<td>
<strong>
CUSTOMIZE IT!
</strong>
. Download the source blocks to your phone by
clicking the button on the right, then upload into App Inventor by choosing
More Actions | Upload Source on the Projects page.
</td>
<td>
<a href="LocationSensorAssets/LocationOnClickTest.zip">
<img alt="" height="116" src="LocationSensorAssets/customize.png" width="211" />
</a>
</td>
</tr>
</table>
<p>
<strong>
UNDERSTAND IT!
</strong>
Here is the user interface and components for the
app:
</p>
<div class="imagecontainer">
<img alt="" height="592" src="LocationSensorAssets/locationOnClickDesigner.png" width="912" />
</div>
<p>
Here are the blocks for the app, with annotation:
</p>
<div class="imagecontainer">
<img alt="" height="631" src="LocationSensorAssets/locationOnClickBlocks.png" width="754" />
</div>
<h2>
Variations
</h2>
<ul>
<li>
The second app illustrates using location data in response to an event. Write
an app that responds to any received text by sending back a text that says, "I'm
driving right now, I'll get back to you later. My location is ..." with the current
location filled in.
</li>
<li>
Write a "breadcrumb" app that tracks your (phone's) whereabouts by recording
each location change. One interesting refinement would be to only record a new
"breadcrumb" if the location has changed by a certain amount.
</li>
</ul>
<blockquote class="notice">
Google is grateful to
<a href="http://appinventorblog.com">
Professor David
Wolber
</a>
, CS Professor at The University of San Francisco, for developing this
tutorial.
</blockquote>
</div>
</div>
</div>
<div class="footer">
<script language = "JavaScript">createFooter();</script><br>
<div class="footer-lastupdate">
<script>
if (document.lastModified != '') {
var m = "Page last updated: " + document.lastModified;
var p = m.length-8;
document.writeln("<center>");
document.write(m.substring(p, 0));
document.writeln("<\/center>");
}
</script>
</div>
</div>
</div>
</div>
</body>
</html>