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.

To display a location on the floor plan, we are going to download a floor plan image from the service and add it to the map as an overlay view.

The IAResourceManager class provides an interface for downloading floor plan images from IndoorAtlas services, The IAFloorPlan class represents floor plan data received from the service.

We will also need a UIImage object to hold the floor plan image.

In the interface section, add two delegates MKMapViewDelegate and IALocationManagerDelegate and define the required instance variables and properties.

@interface AppDelegate () <MKMapViewDelegate, IALocationManagerDelegate> {
	IALocationManager *locationManager;
	IAResourceManager *resourceManager;
	IAFloorPlan *fp;

	UIImage *fpImage;
	MKMapView *map;
	MKMapCamera *camera;

}

@property (strong) MKCircle *circle;
@property (strong) MapOverlay *mapOverlay;
@end

Refer to the previous sections to see how to create a location manager and Apple MapKit Documentation for info on the MapOverlay.

As soon as you get to a location for which you have a floor plan, you will receive a enter region event. Use the fetchFloorPlanWithId:andCompletion method of IAFloorPlanManager to fetch the floor plan data.

If there are no errors, fetch the image data with the fetchFloorPlanImageWithId:andCompletion method.

- (void)indoorLocationManager:(IALocationManager *)manager didEnterRegion:(IARegion *)region
{
	(void) manager;
	NSLog(@"Floor plan changed to %@", region.identifier);
	updateCamera = true

	[resourceManager fetchFloorPlanWithId:region.identifier andCompletion:^(IAFloorPlan *floorPlan, NSError *error) {
		if (!error) {
			self.floorPlan =floorPlan;
			[resourceManager fetchFloorPlanImageWithId:region.identifier andCompletion:^(NSData *imageData, NSError *error){
				 __weak typeof(self) weakSelf = self;
				fpImage = [[UIImage alloc] initWithData:imageData];
				[weakSelf changeMapOverlay];
			}];
		} else {
			NSLog(@"Error fetching floorplan");
		}
	}];
}

Now that you have a floor plan image, you can create the mapOverlay object to be placed on the map.

- (void)changeMapOverlay
{
	if (self.mapOverlay != nil)
		[map removeOverlay:self.mapOverlay];

	// Create mapOverlay. See example application.
	self.mapOverlay = [[MapOverlay alloc] initWithFloorPlan:self.floorPlan];
	[map addOverlay:self.mapOverlay];
}