Wayfinding is done on a graph created by the IA wayfinding graph editor (see Wayfinding graph).
To use the IndoorAtlas Wayfinding in your project, you need to first setup the positioning SDK. After this, you need to add the dependencies to IndoorAtlas Wayfinding.
Update your project Podfile to this:
use_frameworks! target 'project-target-name' do source 'firstname.lastname@example.org:IndoorAtlas/CocoaPods-Specs.git' pod 'IndoorAtlas', '2.8.1' pod 'IndoorAtlasWayfinding', '2.8.0' end
#import <IndoorAtlas/IndoorAtlas.h> #import <IndoorAtlasWayfinding/wayfinding.h>
import IndoorAtlas import IndoorAtlasWayfinding
Using the Wayfinder
To begin, first initialize the IndoorAtlas positioning SDK with valid credentials
static NSString *APIKey = @"api-key-here"; static NSString *APISecret = @"api-secret-here"; // Set IndoorAtlas ApiKey and Secret IALocationManager *locationManager = [IALocationManager sharedInstance]; [locationManager setApiKey:APIKey andSecret:APISecret];
let APIKey = "api-key-here" let APISecret = "api-secret-here" // Set IndoorAtlas ApiKey and Secret var locationManager = IALocationManager.sharedInstance() locationManager.setApiKey(APIKey, andSecret: APISecret)
Then initialize the IndoorAtlas wayfinding (IAWayfinding) using the wayfinding graph:
IAWayfinding *wayfinding = [[IAWayfinding alloc] initWithGraph:graphJson];
var wayfinding = IAWayfinding(graph: graphJson)
To start routing an user to a given destination, first set the destination in the
[wayfinding setDestinationWithLatitude:60.1684003 Longitude:24.9306895 Floor:1];
wayfinding.setDestinationWithLatitude(60.1684003, longitude: 24.9306895, floor: 1)
The route from the current location to destination is obtained by first setting the user’s location and then calling
[wayfinding setLocationWithLatitude:60.1696597 Longitude:24.932497 Floor:1]; NSArray<IARoutingLeg *> *route = [wayfinding getRoute]; // empty if route could not be found, otherwise list of legs
wayfinding.setLocationWithLatitude(60.1696597, longitude: 24.932497, floor: 1) var route = wayfinding.getRoute() // empty if route could not be found, otherwise list of legs
Route is a list of legs where each leg is a straight line segment. The legs also contain pointers to the original nodes and edges of the wayfinding graph, to allow linking to possibly relevant meta data, but using that information is often not mandatory. One leg (IARoutingLeg) in the route list contains the following variables:
IARoutingPoint *begin; IARoutingPoint *end; double length; double direction; NSNumber *edgeIndex;
where the IARoutingPoints contain the following variables:
double latitude; double longitude; int floor; NSNumber *nodeIndex;
nodeIndex point to edges and nodes in the original graph. Note that the index variables can be null for the first and last legs of the route, that present the final connections between the graph and arbitrary off-graph locations.
begin node of the first leg is always the starting location and the
end node of the last leg is the destination. The returned route can also be empty if no possible route was found. This can happen if the given destination or start location floor
number does not exist in the wayfinding graph (e.g., if one would do something like
[wayfinding setLocationWithLatitude:60.4 Longitude:24.9 Floor:1000]).