Skip to content

Navigation

Optional

Needed if your app shows routes or distances between points.

The IPSFramework provides all the tools required to add to your application an Indoor Navigation service that is convenient and easy to use.

Service Availability

The IPS Indoor Navigation service is not available if:

  • Login was not performed;
  • There is no Internet connection.

Requesting a static Route between points of interest

Using IPSNavigation.findRouteInBuilding(_:options:waypoints:finalWaypoint:onRouteReceived:onError:), you can determine an optimal route between points of interest delineated by the IPSWaypoint protocol. This endpoint is mainly used to calculate a static route from entrance to be presented to the user before the position gets locked.

Live Navigation

IPSNavigation can be used as a live navigation service that will automatically react to position updates.

Defining the Waypoints

To start the live navigation, you have to first define the waypoints in the building on which you want to navigate. Each point should be represented using the IPSWaypoint protocol interface.

Use IPSNavigation.setLiveNavigationWayPoints() to define the waypoints.

Observing Route updates

Use IPSNavigation.addLiveNavigationObserver() to add an observer which implements the methods declared in IPSLiveNavigationObserver to manage the route updates and possible errors.

While there is at least one live navigation observer, the Framework will rebuild the route each time there is a significant change in the position of the device. Likewise, the Framework will provide the new Route using the func onLiveNavigationUpdate(route: IPSRoute) method. The contents of the IPSRoute object are described in the next section.

Info

Live navigation updates can be stopped and restarted using IPSNavigation.setLiveNavigationEnabled().

Important

Route updates won't be received while the user position is not locked. See IPSPosition.lockProgress.

Turn-by-Turn Navigation

Experimental API

Turn-by-turn navigation is considered experimental and subject to change or removal in future updates.

In addition to the live-navigation route, the framework can provide step-by-step turn-by-turn instructions. Enable it with IPSNavigation.setTurnByTurnNavigationEnabled() (disabled by default), then add an observer implementing IPSTurnByTurnNavigationObserver via IPSNavigation.addTurnByTurnNavigationObserver():

IPSNavigation.setTurnByTurnNavigationEnabled(true)
IPSNavigation.addTurnByTurnNavigationObserver(self)

// IPSTurnByTurnNavigationObserver implementation
func onLiveNavigationInstructionsUpdate(_ instructions: [IPSTurnByTurnNavigationInstruction]) {
    for instruction in instructions {
        let direction = instruction.direction // e.g. .turn(.right), .continueStraight, .takeElevator(direction:destinationFloor:), .arrived
        let distance = instruction.distance // distance from the previous instruction, in meters
    }
}

func onLiveNavigationManeuversUpdate(_ maneuvers: [IPSTurnByTurnNavigationManeuever]) {
    // Lower-level maneuver updates, if your UI needs more granularity than instructions
}

Each IPSTurnByTurnNavigationInstruction has a direction (IPSTurnByTurnNavigationInstructionDirection — .turn(_:), .turnAround, .turnAroundToPath(_:), .continueStraight, .continueStraightToDestination, .takeEscalator(direction:destinationFloor:), .takeElevator(direction:destinationFloor:), .takeStairs(direction:destinationFloor:), .takeRamp(direction:destinationFloor:), .arrived) and a distance in meters from the previous instruction.

Route Representation

The resulting route is represented by the IPSRoute object. IPSRoute contains:

  • Coordinates of the route in the building (IPSRoute.routeCoordinates);
  • Floor transitions on the route (IPSRoute.floorTransitions);
  • Waypoints used in building of the Route, sorted according to the order in which those points should be visited (IPSRoute.waypoints);
  • Indexes of the Route coordinates, corresponding to the waypoints on the Route, as they appear in IPSRoute.routeCoordinates (IPSRoute.indexOnRoute(of waypoint: IPSWaypoint)) ;
  • Distances, in meters, from the start of the Route, to each waypoint (IPSRoute.distanceFromStart(to waypoint: IPSWaypoint)).
  • Distances, in meters, from the start of the Route, to each floor transition (IPSRoute.distanceFromStartToFloorTransition(_ floorTransition: IPSRouteFloorTransition) -> CGFloat).

Distance Between Objects

To find the distance between two points on the map (for example, between the user and a product), request a route between them with IPSNavigation.findRouteInBuilding() and read IPSRoute.distanceFromStart(to:) for the second waypoint:

let userWaypoint = IPSWaypointModel(id: UUID().uuidString, buildingId: buildingId, floorOrder: userFloorOrder, x: userCoordinate.x, y: userCoordinate.y)
let productWaypoint = IPSWaypointModel(id: UUID().uuidString, buildingId: buildingId, floorOrder: productFloorOrder, x: productCoordinate.x, y: productCoordinate.y)

IPSNavigation.findRouteInBuilding(
    buildingId,
    waypoints: [userWaypoint, productWaypoint],
    onRouteReceived: { route in
        let distance = route.distanceFromStart(to: productWaypoint)
    },
    onError: { error in
    }
)

Info

Both waypoints must be reachable by a walkable route. distanceFromStart(to:) returns -1 if the waypoint isn't on the route.