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: IALocationManager


To start the IndoorAtlas location service

  • Create a shared instance of IALocationManager and 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


Since IndoorAtlas SDK 2.2.x the location updates continue even if the network connection is down for a short time. You will get smoother Wi-Fi hand-overs and better performance when network connection briefly goes offline. This is signaled by a service status of kIAStatusServiceUnavailable.


Advanced features


It is also possible to filter the location updates by distance. (see the API documentation).