Tip: Indoor-outdoor transitions are demonstrated in the Google Maps Overlay code example

Accurate indoor-outdoor detection requires GPS. In IndoorAtlas SDK versions 2.6 and above, the platform location scanning needed for this purpose is managed by the SDK, but you need to provide the necessary permissions:


<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


Also remember to query for the user’s permission as described in the SDK setup section.



Note!
Indoor-outdoor detection is also available in SDK versions 2.3 and above but in versions <= 2.5, you need to manually request for GPS platform locations to use it. The IndoorAtlas SDK will then listen the updates using a PASSIVE_PROVIDER.


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


private IARegion.Listener mRegionListener = new IARegion.Listener() {
    // when null, we are not on any mapped area
    // this information can be used for indoor-outdoor detection
    IARegion mCurrentFloorPlan = null;

    @Override
    public void onEnterRegion(IARegion region) {
        if (region.getType() == IARegion.TYPE_FLOOR_PLAN) {
            // triggered when entering the mapped area of the given floor plan
            Log.d(TAG, "Entered " + region.getName());
            Log.d(TAG, "floor plan ID: " + region.getId());
            mCurrentFloorPlan = region;
        }
        else if (region.getType() == IARegion.TYPE_VENUE) {
            // triggered when near a new location
            Log.d(TAG, "Location changed to " + region.getId());
        }
    }

    @Override
    public void onExitRegion(IARegion region) {
        // leaving a previously entered region
        if (region.getType() == IARegion.TYPE_FLOOR_PLAN) {
            mCurrentFloorPlan = null;
            // 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
        }
    }
};


Location and floor plan regions


In the above code snippet, there are two types of region entry events. The TYPE_FLOOR_PLAN 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 TYPE_VENUE 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 calling setLocation method of IALocationManager with an explicit venue (IARegion.venue) or floor plan (IARegion.floorPlan). 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:


private IARegion.Listener mRegionListener = new IARegion.Listener() {
    IARegion mCurrentVenue = null;
    IARegion mCurrentFloorPlan = null;

    @Override
    public void onEnterRegion(IARegion region) {
        if (region.getType() == IARegion.TYPE_FLOOR_PLAN) {
            // automatically detected floor plan
            mCurrentFloorPlan = region;
        }
        else if (region.getType() == IARegion.TYPE_VENUE) {
          if (mCurrentVenue == null) {
            // lock to the first detected venue
            mIALocationManager.setLocation(IALocation.Builder()
                .withRegion(region).build());
          }
          mCurrentVenue = region;
        }
    }

    @Override
    public void onExitRegion(IARegion region) {}
};