Using the location sensor with App Inventor Level

  • Slides: 9
Download presentation
Using the location sensor with App Inventor Level 3 Find address, Display circle for

Using the location sensor with App Inventor Level 3 Find address, Display circle for location accuracy, Enable / disable internet dependent functions, Display location status change events (optional) Mobile CSP 2016 Pierre Huguet pierre. huguet 50@gmail. com

Level 3 addons • Level 3 adds : Get address from location sensor Ø

Level 3 addons • Level 3 adds : Get address from location sensor Ø new label, new button and event handler in main menu. Display accuracy circle around current location Button to enable/disable functions which require internet Ø new button and event handler in main menu. 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New components for level 3 New Internet availability Find address web functions on/off toggle

New components for level 3 New Internet availability Find address web functions on/off toggle 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New blocks for level 3 (1/5) find address with the location sensor "current address"

New blocks for level 3 (1/5) find address with the location sensor "current address" attribute • The "get current address" block returns the adddress corresponding to the current location. • Simple … BUT : – You must stay aware that this calls a web service, – Scripts containing this block will not return control to the user before completion (or internet time out), and may block if No internet – This is why we use a separate button for "address" queries (we will see a better solution in level 4) • The address button handler 1. 2. Gets the replaces line feeds, by commas and updates the Lbl. Adrress for display 3. Then sets label visible 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New blocks for level 3 (2/5) display accuracy circle : compute pixel size •

New blocks for level 3 (2/5) display accuracy circle : compute pixel size • How to draw a circle with radius = accuracy in meters ? – Solution 1 : translate circle to lat-long and plot with static maps API – Solution 2 : translate radius to pixels and draw circle in the canvas • We have chosen solution 2 : – Pixel size depends of the zoom factor. • Zoom level 0 corresponds to world coverage with 256 pixels. • at geographic scales with low zoom values pixels are square in degrees, • at topographic scales with high zoom values, pixels are square in meters. • at topographic scales, pixel size in meters can be computed with the following procedure (see the mapping tutorial for more info) : 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New blocks for level 3 (3/5) display accuracy circle : draw circle with radius

New blocks for level 3 (3/5) display accuracy circle : draw circle with radius = accuracy • Circle center must be at last location which is at canvas center • Circle radius in pixels = accuracy in meters / pixel size in meters • Circle color is chosen as blue with a transparency level of 50/255 • This leads to add Paint. Color set and Draw. Circle blocks, in the display. Map procedure after setting the canvas Background Image. 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New blocks for level 3 (4/5) internet / no internet button toggle • Functions

New blocks for level 3 (4/5) internet / no internet button toggle • Functions which require internet should not be called when internet access is lost (which routinely occurs). Note : we will see Non blocking function calls in level 4 • The / button handler will set and hide or show buttons which call these functions. – – show/hide zoom button show/hide unzoom button show/hide address button show/hide display toggle and switch to list display 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New blocks for level 3 (5/5) display location sensor status when it changes •

New blocks for level 3 (5/5) display location sensor status when it changes • Location sensor status changes are not very frequent and do not seem to be very useful. It may however be useful if you encouter problems. • The following location sensor "status changed" event handler merely displays status and provider. 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

Level 3 : blocks overview 09/2016 Location and GPS tutorial for App Inventor, pierre.

Level 3 : blocks overview 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com