vendredi 31 janvier 2025

Références App Inventor pour application GPS

Attention : la première réception du signal GPS et calcul de position demande une trentaine de secondes. Après, le changement de position est plus rapide, environ 5 secondes


Attention : la sauvegarde sur fichier :

avec Companion : mettre le nom du fichier avec un slash devant /monfichier.gpx et il est sauvegardé dans :
Android/data/edu.mit.appinventor.aicompanion3/files/monfichier.gpx
après compilation et exécution du fichier compilé ; le fichier monfichier.gpx est sauvegardé dans :
Android/data/appinventor.ai_monCompte.monProjet/files/monfichier.gpx

Go to MIT App Inventor and sign in with your Google account.

Start a new project and give it a name, e.g., "GPX_Recorder".

Design the User Interface:


Add a Button component for starting and stopping the recording.

Add a Label component to display the status.

Add a TinyDB component for storing the GPX data.

Add a LocationSensor component to get the GPS coordinates.

Create the blocks to handle the logic:


Here's the layout and the logic for the app:


Designer View

Drag and drop the following components:

Button

Text: "Start Recording"

Name: StartButton

Button

Text: "Stop Recording"

Name: StopButton

Button

Text: "Save GPX File"

Name: SaveButton

Label

Text: "Status: Not recording"

Name: StatusLabel

LocationSensor

Name: LocationSensor1

TinyDB

Name: TinyDB1


Blocks View

Initialize the components and variables:


blocks

// Initialize global variables

initialize global recording to false

initialize global gpxData to "<gpx version='1.1' creator='AppInventor'><trk><name>Track</name><trkseg>"


// Start Button Click Event

when StartButton.Click

  set global recording to true

  set StatusLabel.Text to "Status: Recording"

  call LocationSensor1.Start


// Stop Button Click Event

when StopButton.Click

  set global recording to false

  set StatusLabel.Text to "Status: Not recording"

  call LocationSensor1.Stop


// Save Button Click Event

when SaveButton.Click

  call TinyDB1.StoreValue

    tag: "gpxData"

    value: join (global gpxData) "</trkseg></trk></gpx>"

  set StatusLabel.Text to "Status: GPX File Saved"


// LocationSensor Location Changed Event

when LocationSensor1.LocationChanged

  if global recording

    set global gpxData to join (global gpxData) "<trkpt lat='" (LocationSensor1.Latitude) "' lon='" (LocationSensor1.Longitude) "'><ele>" (LocationSensor1.Altitude) "</ele><time>" (Clock.Now) "</time></trkpt>"


Aucun commentaire: