Fetching floor plan images from IndoorAtlas

Automatic floor plan detection is handled with IARegion events as described in the floor detection chapter. For your convenience, IndoorAtlas SDK also provides an API for fetching the floor plan images that you have stored in our cloud in the mapping phase.

If you use an indoor map provider such as Micello, you probably want to skip this and use their API for displaying the floor plan instead.

  • An ImageView instance is created in the application layout resource file. It will hold the bitmap image, when we get it.
  • The IAFloorPlan class represents floor plan data. It has a url field pointing to the floor plan image.
  • The IAResourceManager class provides an interface to fetch IAFloorPlan objects from IndoorAtlas services.

Create an instance of the IAResourceManager class using its create() method.

public class ResourceManagerActivity extends AppCompatActivity {
    private IALocationManager mLocationManager;
    private IAResourceManager mResourceManager;
    private ImageView mFloorPlanImage;

    // ...

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_floor_plan_manager);
        mFloorPlanImage = (ImageView) findViewById(R.id.image);
        // ...
        // Create instance of IAFloorPlanManager class
        mFloorPlanManager = IAResourceManager.create(this);
    }
}

Register a Region listener:

private IARegion.Listener mRegionListener = new IARegion.Listener() {
    @Override
    public void onEnterRegion(IARegion region) {
        if (region.getType() == IARegion.TYPE_FLOOR_PLAN) {
            fetchFloorPlan(region.getId());
        }
    }

    @Override
    public void onExitRegion(IARegion region) {
        // leaving a previously entered region
    }
};

mIALocationManager.registerRegionListener(mRegionListener);

Request location updates

To fetch the floor plan, call the fetchFloorPlanWithId() method of the IAResourceManager class. It returns an instance of IATask<IAFloorPlan>. IATask<R> and IAResultCallback<R> are helper interfaces to work with asynchronous operations.

private void fetchFloorPlan(String id) {
    // Cancel pending operation, if any
    if (mPendingAsyncResult != null && !mPendingAsyncResult.isCancelled()) {
        mPendingAsyncResult.cancel();
    }

    mPendingAsyncResult = mResourceManager.fetchFloorPlanWithId(id);
    if (mPendingAsyncResult != null) {
        mPendingAsyncResult.setCallback(new IAResultCallback<IAFloorPlan>() {
            @Override
            public void onResult(IAResult<IAFloorPlan> result) {
                Logger.d(TAG, "onResult: %s", result);

                if (result.isSuccess()) {
                    handleFloorPlanChange(result.getResult());
                } else {
                    // do something with error
                    Toast.makeText(FloorPlanManagerActivity.this,
                        "loading floor plan failed: " + result.getError(), Toast.LENGTH_LONG)
                        .show();
                }
            }
        }, Looper.getMainLooper()); // deliver callbacks in main thread
    }
}

If we don’t have any errors, download the image. For convenience here, we use the third-party Picasso library.

import com.squareup.picasso.Picasso;
// ...
private void handleFloorPlanChange(IAFloorPlan newFloorPlan) {
    Picasso.with(this)
        .load(newFloorPlan.url)
        .into(mFloorPlanImage);
}