AWARE: Locations
The locations sensor provides the best location estimate for the users’ current location, automatically. The location data is provided by Core Location.
Requirements
iOS 10 or later.
Installation
com.aware.ios.sensor.locations is available through CocoaPods.
- To install it, simply add the following line to your Podfile:
pod 'com.awareframework.ios.sensor.locations'- Import com.aware.ios.sensor.locations library into your source code.
import com_awareframework_ios_sensor_locations- Open your project ( *.xcworkspace ) and add
NSLocationAlwaysAndWhenInUseUsageDescriptionandNSLocationWhenInUseUsageDescriptioninto 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 =null)frequency: Inthow frequent to check the location, in seconds. By default, every 180 seconds. Setting to 0 (zero) will keep the GPS location tracking always on. (default = 180)accuracy: Intthe minimum acceptable accuracy of GPS location, in meters. By default, 150 meters. Setting to 0 (zero) will keep the GPS location tracking always on. (default = 150)expirationTime: Int64the amount of elapsed time, in seconds, until the location is considered outdated. By default, 300 seconds. (default = 300)saveAll: BooleanWhether to save all the location updates or not. (default =false)enabled: BooleanSensor is enabled or not. (default =false)debug: Booleanenable/disable logging toLogcat. (default =false)label: StringLabel for the data. (default = "")deviceId: StringId of the device that will be associated with the events and the sensor. (default = "")dbEncryptionKeyEncryption key for the database. (default =null)dbType: EngineWhich db engine to use for saving data. (default =Engine.DatabaseType.NONE)dbPath: StringPath of the database. (default = "aware_locations")dbHost: StringHost for syncing the database. (default =null)
Broadcasts
Fired Broadcasts
LocationsSensor.ACTION_AWARE_LOCATIONSfired when new location available.LocationsSensor.ACTION_AWARE_GPS_LOCATION_ENABLEDfired when GPS location is active.LocationsSensor.ACTION_AWARE_GPS_LOCATION_DISABLEDfired 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 theLocationsSensor.EXTRA_LABELfield of the intent extras.
Data Representations
Locations Data
Contains the locations profiles.
| Field | Type | Description |
|---|---|---|
| latitude | Double | The latitude in degrees. |
| longitude | Double | The longitude in degrees. |
| course | Double | The direction in which the device is traveling, measured in degrees and relative to due north. |
| speed | Float | The instantaneous speed of the device, measured in meters per second. |
| altitude | Double | The altitude, measured in meters. |
| floor | Double? | The logical floor of the building in which the user is located. |
| horizontalAccuracy | Double | The radius of uncertainty for the location, measured in meters. |
| verticalAccuracy | Double | The accuracy of the altitude value, measured in meters. |
| deviceId | String | AWARE device UUID |
| label | String | Customizable label. Useful for data calibration or traceability |
| timestamp | Long | Unixtime milliseconds since 1970 |
| timezone | Int | Rimezone of the device |
| os | String | Operating system of the device (e.g., ios) |
Example usage
// To initialize the sensor
let locationSensor = LocationsSensor.init(LocationsSensor.Config().apply{config in
config.sensorObserver = Observer()
config.debug = true
config.dbType = DatabaseType.REALM
// more configuration...
})
// To start the sensor
locationSensor?.start()
// To stop the sensor
locationSensor?.stop()class Observer:LocationsObserver {
func onLocationChanged(data: LocationsData) {
// your code here
}
}Author
Yuuki Nishiyama, [email protected]
Related links
License
Copyright (c) 2021 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.