Skip to content

Repository files navigation

AWARE: Locations

Swift Package Manager compatible

The locations sensor provides the best location estimate for the users’ current location, automatically. The location data is provided by Core Location.

Requirements

iOS 13 or later.

Installation

  1. Open Package Manager Windows

    • Open Xcode -> Select Menu Bar -> File -> App Package Dependencies...
  2. Find the package using the manager

    • Select Search Package URL and type https://github.com/awareframework/com.awareframework.ios.sensor.locations.git
  3. Import the package into your target.

  4. Add NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription into Info.plist.

Public Functions

LocationsSensor

  • init(config:LocationsSensor.Config?): Initializes the locations sensor with the optional configuration.
  • start(): Starts the locations sensor with the optional configuration.
  • stop(): Stops the service.

LocationsSensor.Config

Class to hold the configuration of the sensor.

Fields

  • sensorObserver: LocationsObserver?: Callback for live data updates. (default = nil)
  • sampleIntervalSeconds: Double: How often to check the location, in seconds. By default, every 180 seconds. (default = 180)
  • accuracy: Int: the minimum acceptable accuracy of GPS location, in meters. By default, 100 meters. (default = 100)
  • distanceFilter: Double: The minimum distance, in meters, before Core Location sends another standard location update. Set 0 to disable distance filtering. (default = 0)
  • expirationTime: Int64: the amount of elapsed time, in seconds, until the location is considered outdated. By default, 300 seconds. (default = 300)
  • saveAll: Bool: Whether to save all the location updates or not. (default = true)
  • statusGps: Bool: Whether to use continuous GPS location tracking via startUpdatingLocation. (default = true)
  • statusSignificantLocationChanges: Bool: Whether to also use significant-location-change monitoring as a background wake-up/recovery mechanism. Standard location updates remain enabled when statusGps is true. (default = true)
  • enabled: Bool: Sensor is enabled or not. (default = false)
  • debug: Bool: Enable/disable logging. (default = false)
  • label: String: Label for the data. (default = "")
  • deviceId: String: Id of the device that will be associated with the events and the sensor. (default = "")
  • dbEncryptionKey: String?: Encryption key for the database. (default = nil)
  • dbType: DatabaseType: Which db engine to use for saving data. (default = .none)
  • dbPath: String: Path of the database. (default = "aware_locations")
  • dbHost: String?: Host for syncing the database. (default = nil)

Broadcasts

Fired Broadcasts

  • LocationsSensor.ACTION_AWARE_LOCATIONS: fired when new location available.
  • LocationsSensor.ACTION_AWARE_GPS_LOCATION_ENABLED: fired when GPS location is active.
  • LocationsSensor.ACTION_AWARE_GPS_LOCATION_DISABLED: fired when GPS location disabled.

Received Broadcasts

  • LocationsSensor.ACTION_AWARE_LOCATIONS_START: received broadcast to start the sensor.
  • LocationsSensor.ACTION_AWARE_LOCATIONS_STOP: received broadcast to stop the sensor.
  • LocationsSensor.ACTION_AWARE_LOCATIONS_SYNC: received broadcast to send sync attempt to the host.
  • LocationsSensor.ACTION_AWARE_LOCATIONS_SET_LABEL: received broadcast to set the data label. Label is expected in the LocationsSensor.EXTRA_LABEL field of the intent extras.

Data Representations

Locations Data

Contains the locations profiles.

FieldTypeDescription
latitudeDoubleThe latitude in degrees.
longitudeDoubleThe longitude in degrees.
courseDoubleThe direction in which the device is traveling, measured in degrees and relative to due north.
speedDoubleThe instantaneous speed of the device, measured in meters per second.
altitudeDoubleThe altitude, measured in meters.
floorIntThe logical floor of the building in which the user is located.
horizontalAccuracyDoubleThe radius of uncertainty for the location, measured in meters.
verticalAccuracyDoubleThe accuracy of the altitude value, measured in meters.
deviceIdStringAWARE device UUID
labelStringCustomizable label. Useful for data calibration or traceability
timestampInt64Unixtime milliseconds since 1970
timezoneIntTimezone of the device
osStringOperating system of the device (e.g., ios)
jsonVersionIntJSON schema version

Heading Data

Contains compass/heading data.

FieldTypeDescription
magneticHeadingDoubleThe heading (in degrees) relative to magnetic north.
trueHeadingDoubleThe heading (in degrees) relative to true north.
headingAccuracyDoubleThe maximum deviation (in degrees) between reported and true heading.
xDoubleThe geomagnetic data (x-axis) measured in microteslas.
yDoubleThe geomagnetic data (y-axis) measured in microteslas.
zDoubleThe geomagnetic data (z-axis) measured in microteslas.
deviceIdStringAWARE device UUID
labelStringCustomizable label. Useful for data calibration or traceability
timestampInt64Unixtime milliseconds since 1970
timezoneIntTimezone of the device
osStringOperating system of the device (e.g., ios)
jsonVersionIntJSON schema version

Location Event Data

Contains Core Location lifecycle events, including authorization changes, failures, and pause/resume callbacks.

FieldTypeDescription
eventTypeStringEvent type: authorization_changed, failed, paused, or resumed.
messageStringHuman-readable event detail.
errorDomainStringError domain for failure events.
errorCodeIntError code for failure events.
authorizationStatusStringCurrent Core Location authorization status.
accuracyAuthorizationStringCurrent accuracy authorization on iOS 14 and later.
latitudeDoubleLast known latitude, if available.
longitudeDoubleLast known longitude, if available.
horizontalAccuracyDoubleLast known horizontal accuracy, if available.
deviceIdStringAWARE device UUID
labelStringCustomizable label. Useful for data calibration or traceability
timestampInt64Unixtime milliseconds since 1970
timezoneIntTimezone of the device
osStringOperating system of the device (e.g., ios)
jsonVersionIntJSON schema version

Example Usage

// To initialize the sensor
letlocationSensor=LocationsSensor.init(LocationsSensor.Config().apply{ config in
config.sensorObserver =Observer()
config.debug =true
config.dbType =.sqlite
// more configuration...
})
// To start the sensor
locationSensor?.start()
// To stop the sensor
locationSensor?.stop()
classObserver:LocationsObserver{func onLocationChanged(data:LocationsData){
// your code here
}}

Author

Yuuki Nishiyama (The University of Tokyo), nishiyama@csis.u-tokyo.ac.jp

Related Links

License

Copyright (c) 2025 AWARE Mobile Context Instrumentation Middleware/Framework (http://www.awareframework.com)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages