The location sensor can be used to access the location of the device. The sensor combines the WiFi, cellular, and GPS data from the device to determine the location. This data can be accessed using the location tag. 

The location data is stored inside of an inherent vector called value inside of the onValueChanged event. value is an object with the following fields:

  1. Latitude - measured in degrees
  2. Longitude - measured in degrees
  3. Altitude - measured in metres above sea level
  4. Speed - measured in metres per second
  5. Bearing - measured in degrees clockwise from true North
  6. Timestamp - object with fields:
    • Day
    • Month
    • Year
    • Hour
    • Minute
    • Second
    • Milisecond
    • DayOfWeek
    • DayOfYear
    • Ticks

The location sensor also has a field to set the accuracy of the data. The default accuracy balances power consumption with data accuracy. The accuracy settings are as follows:

  1. best
  2. high - accuracy within approximately 3 m
  3. good - accuracy within approximately 10 m
  4. balanced - accuracy within approximately 100 metres
  5. low - accuracy within approximately 1 km
  6. lowest - accuracy within approximately 3 km

As with simulations, qdex will not start to read location data until the sensor is started using the Start() method, or signaled from a simulation.

The location sensor may take upwards of 1-2 minutes to read data.

Example 1

This example uses a simulation to signal the location sensor on a device. The duration of the simulation is defined so that the location sensor can time out, thus reducing battery power consumption.

The simulation reads the location data every 8 seconds to check for updates. Once the data changes from the default value of 0, the labels are updated to reflect the sensor numbers. The notify popup is used to let users know that the sensor is on, but needs time to calculate the location data.

<location accuracy="best" name="myLocation" />

<button name="startButton" content="Get Location Data">
    notify('Starting Location Sensor')
    startButton.Style.Visibility = "hidden"

<simulation name="mySim" period="8" duration="180">
    startButton.Style.Visibility = "visible"
      <signal ref="section1.myLocation" width="5" />
      <system name="myOutput">
        <input name="location" width="5" />
          if myLocation.Latitude == 0 and myLocation.Longitude == 0 and myLocation.Altitude == 0 then
            latitudeLabel.Text = string.format("Latitude: %.2f degrees", myLocation.Latitude)
            longitudeLabel.Text = string.format("Longitude: %.2f degrees", myLocation.Longitude)
            altitudeLabel.Text = string.format("Altitude: %.2f metres above sea level", myLocation.Altitude)
            speedLabel.Text = string.format("Speed: %.2f m/s", myLocation.Speed)
            bearingLabel.Text = string.format("Bearing: %.2f degrees CW from North", myLocation.Bearing)
            startButton.Style.Visibility = "visible"

<label name="latitudeLabel" />
<label name="longitudeLabel" />
<label name="altitudeLabel" />
<label name="speedLabel" />
<label name="bearingLabel" />
<label name="timestampLabel" />