The central component of the IndoorAtlas location framework is theIALocationManager class, which provides access to IndoorAtlas services.
The IALocationManagerDelegate protocol defines the method to receive location updates. Define the location manager property in the interface section and add the delegate
Obj C:
@interface AppDelegate () <IALocationManagerDelegate> @property (nonatomic, strong) IALocationManager *locationManager; @end
Swift:
class AppDelegate: IALocationManagerDelegate {
var locationManager: IALocationManagerTo start the IndoorAtlas location service
- Create a shared instance of
IALocationManagerand point the delegate to the receiver. - Set the IndoorAtlas ApiKey and Secret (see here).
- Request location updates.
Here is a code snippet for authenticating and requesting location updates:
Obj C:
- (void)authenticateAndRequestLocation
{
// Get IALocationManager shared instance and point delegate to receiver
self.locationManager = [IALocationManager sharedInstance];
self.locationManager.delegate = self;
// Set IndoorAtlas API key and secret
[self.locationManager setApiKey:kAPIKey andSecret:kAPISecret];
// Request location updates
[self.locationManager startUpdatingLocation];
}Swift:
func authenticateAndRequestLocation() {
// Get IALocationManager shared instance and point delegate to receiver
locationManager = IALocationManager.sharedInstance()
locationManager.delegate = self
// Set IndoorAtlas API key and secret
locationManager.setApiKey(kAPIKey, andSecret: kAPISecret)
// Request location updates
locationManager.startUpdatingLocation()
}When location data is received from the service, the location manager reports events to the indoorLocationManager:didUpdateLocations:method of its delegate.
Obj C:
// Delegate method from the IALocationManagerDelegate protocol
- (void)indoorLocationManager:(IALocationManager *)manager didUpdateLocations:(NSArray *)locations
{
(void)manager;
CLLocation *l = [(IALocation *)locations.lastObject location];
NSLog(@"position changed to coordinate: %.6fx%.6f",
l.coordinate.latitude, l.coordinate.longitude);
}Swift:
// Delegate method from the IALocationManagerDelegate protocol.
func indoorLocationManager(_ manager: IALocationManager, didUpdateLocations locations: [Any]) {
let l = locations.last as! IALocation
if let newLocation = l.location?.coordinate {
print("Position changed to coordinate: \(newLocation.latitude) \(newLocation.longitude)")
}
}Location updates during temporary network connection loss
The new SDKs, 3.0 and above runs the state-of-the-art positioning algorithms on the device. Accurate geomagnetic-aided tracking is available everywhere – also when your device is offline.
Read more here:
https://www.indooratlas.com/
Advanced features
It is also possible to filter the location updates by distance. (see the API documentation).