Using the location sensor with App Inventor Level

  • Slides: 11
Download presentation
Using the location sensor with App Inventor Level 4 Terrain Altitude from web services,

Using the location sensor with App Inventor Level 4 Terrain Altitude from web services, Non blocking version of Web functions, Save and load tracks (local database), Display location status change events (optional) Mobile CSP 2016 Pierre Huguet pierre. huguet 50@gmail. com

Level 4 addons • Level 4 adds : Terrain (or ground) altitude in meters

Level 4 addons • Level 4 adds : Terrain (or ground) altitude in meters from Web service and world terrain database Non blocking version of internet dependent functions (map display, address query) Load and save track (list of previous locations) Display Location status changes (not very useful may be skipped) 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New components for level 4 New arrangement, label and button to display location status

New components for level 4 New arrangement, label and button to display location status change (invisible by default) New Terrain Z button New Internet buttons removed New load and save buttons 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New blocks for level 4 (1/5) find Terrain/ground altitude from Web service/world database •

New blocks for level 4 (1/5) find Terrain/ground altitude from Web service/world database • This illustrates use of Web services : here the Google elevation API https: //developers. google. com/maps/documentation/elevation/intro • The general principle is to : – use an App inventor Web component, named : Web. Terrain. Z – send a Get query for the altitude at given location, then release program control, – handle the Web. Terrain. Z. Got. Text event which triggers when result comes back. Note that with this 2 steps, your App is not blocked while waiting for the result • Step 1 : query when clicking – url is set to the elevation API URL with added location parameters 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New blocks for level 4 (2/5) find Terrain/ground altitude from Web service/world database •

New blocks for level 4 (2/5) find Terrain/ground altitude from Web service/world database • Step 2 : Process result when Web. Terrain. Z. Got. Text triggers – Response returned has the following XML format, – after checking the response code, we extract what is between the <elevation> and </elevation> tags, then display it with adequate decimal formatting. 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New blocks for level 4 (3/5) Non blocking version of the find address call

New blocks for level 4 (3/5) Non blocking version of the find address call • We can do the same for "Address" which is currently an attribute of the location sensor, hiding a Web query, … possibly blocking. • We use the same 2 step solution with the Google Geocode API : – Step 1 : query Web server when clicking Btnfind Address – Step 2 : Parse result when Web. Address. Got. Text triggers. The difference with "terrain. Z" is that split is done on the <formatted_address> tag 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New blocks for level 4 (4/5) display map with a non blocking call •

New blocks for level 4 (4/5) display map with a non blocking call • Setting the map URL in the display. Map procedure may also block while waiting for result • We will use the same 2 steps, but will keep the result as a file, then display it and delete it : 1. Issue a web query instead of setting the map canvas URL, asking to save the result in a file. 2. Handle the Web. Image. Got. File event : - set the canvas image, - delete file - complete display Note that the accuracy circle must still be drawn after setting the canvas image 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New blocks for level 4 (3/5) error handling on internet calls • What happens

New blocks for level 4 (3/5) error handling on internet calls • What happens if internet access is lost ? (build and load apk then set your phone to airplane to try it) An error will be returned => • You can use an error event handler to handle it within your App to improve display You can use this error handler for many cases 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New blocks for level 4 (5/5) load and save track • You may wish

New blocks for level 4 (5/5) load and save track • You may wish to record and reload tracks The length of URL is however limited to 2048 characters, which limits the number of points. • & buttons and a Tiny. DB 1 component are added • Load button handler • Will replace current track by previously saved one • Save button handler • Will save current track 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

New blocks for level 4 (5/5) handle and display location status changes • The

New blocks for level 4 (5/5) handle and display location status changes • The location status changes when the location becomes available or unavailable (ex: turned on or off) • You can display this information and clear it with the following blocks using the horizontal arrangement. • You can check messages by setting the location sensor on and off. 09/2016 Location and GPS tutorial for App Inventor, pierre. huguet 50@gmail. com

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

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