Tip: Indoor-outdoor transitions are demonstrated in the Indoor-outdoor code example (Objective-C) and Indoor-outdoor code example (Swift).


Accurate indoor-outdoor detection requires accurate platform locations. In IndoorAtlas SDK versions 2.6 and above, the platform location scanning needed for this purpose is controlled by the SDK, and you only need to provide the necessary permissions as explained in SDK setup.



Note!
Indoor-outdoor detection is also available in SDK versions 2.3 and above but in versions <= 2.5, platform locations are requested at a fixed accuracy.


Like automatic floor detection, indoor-outdoor transitions are signaled with the IARegion events.


Obj C:


// Handling region enter events
- (void)indoorLocationManager:(IALocationManager *)manager didEnterRegion:(IARegion *)region
{
    switch (region.type) {
        case kIARegionTypeVenue:
            // Triggered when near a new location
            NSLog(@"Entered venue %@", region.identifier);
            break;
        case kIARegionTypeFloorPlan:
            // Triggered when entering the mapped area of the given floor plan
            NSLog(@"Entered floor plan %@", region.identifier);
            break;
    }
}

// Handling region exit events
- (void)indoorLocationManager:(IALocationManager *)manager didExitRegion:(IARegion *)region
{
    // Leaving a previously entered region
    switch (region.type) {
        case kIARegionTypeVenue:
            // Triggered when moving away from the vicinity of a location
            NSLog(@"Exit venue %@", region.identifier);
            break;
        case kIARegionTypeFloorPlan:
            // Notice that a change of floor plan (e.g., floor change)
            // is signaled by an exit-enter pair so ending up here
            // does not yet mean that the device is outside any mapped area
            NSLog(@"Exit floor plan %@", region.identifier);
            break;
    }
}


Swift:


// Handling region enter events
func indoorLocationManager(_ manager: IALocationManager, didEnter region: IARegion) {

    switch region.type {
    case .iaRegionTypeVenue:
        // Triggered when near a new location
        print("Entered venue \(region.identifier)")
    case .iaRegionTypeFloorPlan:
        // Triggered when entering the mapped area of the given floor plan
        print("Entered floor plan \(region.identifier)")
    default:
        break
    }
}

// Handling region exit events
func indoorLocationManager(_ manager: IALocationManager, didExitRegion region: IARegion) {

    // Leaving a previously entered region
    switch region.type {
    case .iaRegionTypeVenue:
        // Triggered when moving away from the vicinity of a location
        print("Exit venue \(region.identifier)")
    case .iaRegionTypeFloorPlan:
        // Notice that a change of floor plan (e.g., floor change)
        // is signaled by an exit-enter pair so ending up here
        // does not yet mean that the device is outside any mapped area
        print("Exit floor plan \(region.identifier)")
    default:
        break
    }
}



The IALocationManager delegate must be set before using these events.


Obj C:


self.locationManager.delegate = self;


Swift:


locationManager.delegate = self



Location and floor plan regions


In the above code snippet, there are two types of region entry events. 

  • The kIARegionTypeFloorPlan entry events are triggered when the user actually enters the mapped area of the floor plan. In almost all cases, this corresponds to physically entering the building. 
  • The kIARegionTypeVenue events are emitted a lot earlier, between 100 and 200 meters of the location (a.k.a. venue). This is meant as a heads-up to enable pre-loading of data. The venue entry events are also useful in the case when one wishes to disable automatic indoor-outdoor detection.



Floor plan and venue regions



Disabling indoor-outdoor detection


Automatic indoor-outdoor detection can be disabled by setting the location by either locationWithVenueId with an explicit venue id or locationWithFloorPlanId with an explicit floor plan id. This tells the SDK that you are certain that the user is inside the given building.


Even if you with to disable IndoorAtlas indoor-outdoor detection, you can still enable automatic floor detection by locking the first detected venue as follows:


Obj C:


- (void)indoorLocationManager:(IALocationManager *)manager didEnterRegion:(IARegion *)region
{
    if (region.type == kIARegionTypeVenue) {
        IALocation *loc = [IALocation locationWithVenueId:region.identifier andFloor:nil];
        self.locationManager.location = loc;
    }
}


Swift:


func indoorLocationManager(_ manager: IALocationManager, didEnter region: IARegion) {

    if region.type == .iaRegionTypeVenue {
        let loc = IALocation(venueId: region.identifier, andFloor: nil)
        self.locationManager.location = loc
    }
}