Skip to main content

Itineraries

info

The know the implemented features and the coverage please refer to the Routing API page

The itineraries used in the WemapSDKs are generated by the Wemap Routing API. The way you interact with the Wemap Routing API varies depending on which WemapSDK you use.

When you use:

  • WemapMapSDK use:
    • MapNavigationManaging protocol to compute itineraries and start navigation immediately.
    • ItineraryManager class to compute and preview itineraries before starting a navigation.
  • WemapGeoARSDK use:
    • ARNavigationManaging protocol to compute itineraries and start navigation immediately.
  • WemapCoreSDK use:
    • ItineraryServicing protocol to compute itineraries.

To generate an itinerary, you'll need to provide a destination, optionally origin and other options depending on which WemapSDK you use. You also can use the ItinerarySearchRules struct to set a few search rules. Wemap Routing API provides different travel modes for itinerary computation: walk, car and bike. Bike travel mode also can have TravelMode.Preference: default, safest, fastest and tourism.

Map Navigation Manager (WemapMapSDK)

To generate an itinerary and start navigation, you'll need to obtain an instance implementing MapNavigationManaging from MapView.

func startNavigation() {

let origin = Coordinate(latitude: 43.610628, longitude: 3.876654)
let destination = Coordinate(latitude: 43.609011, longitude: 3.917091)

let navigationOptions = NavigationOptions(stopWhenArrivedAtDestination: false) // NavigationOptions available for Map and AR SDKs
let itineraryOptions = ItineraryOptions(indoorLine: .init(color: .red)) // ItineraryOptions available only for WemapMapSDK
let searchRules: ItinerarySearchRules = .wheelchair // ItinerarySearchRules available for all SDKs

mapView.navigationManager
.startNavigation(
origin: origin, destination: destination,
travelMode: .walk, // can be omitted because it's default mode
options: navigationOptions, searchRules: searchRules, itineraryOptions: itineraryOptions,
timeout: .seconds(10) // default value is .seconds(30)
)
.subscribe(
onSuccess: { _ in
debugPrint("Successfully started navigation from: \(origin) to: \(destination)")
self.mapView.userTrackingMode = .follow // track user movements
},
onFailure: { error in
debugPrint("Failed to start navigation from \(origin) to: \(destination) with error: \(error)")
}
).disposed(by: disposeBag)
}

Itinerary manager (WemapMapSDK)

To generate an itinerary for preview, you'll need to obtain an instance of ItineraryManager class from MapView.

func getItinerariesForPreview() {

let origin = Coordinate(latitude: 43.610628, longitude: 3.876654)
let destination = Coordinate(latitude: 43.609011, longitude: 3.917091)

let searchRules: ItinerarySearchRules = .wheelchair // ItinerarySearchRules available for all SDKs

mapView.itineraryManager
.getItineraries(
origin: origin, destination: destination,
travelMode: .walk, // can be omitted because it's default mode
searchRules: searchRules
)
.subscribe(
onSuccess: { itineraries in
debugPrint("Successfully received itineraries from: \(origin) to: \(destination)")
self.mapView.userTrackingMode = .follow // track user movements
self.mapView.itineraryManager.addItinerary(itineraries.first!) // draw preview
},
onFailure: { error in
debugPrint("Failed to receive itineraries from \(origin) to: \(destination) with error: \(error)")
}
).disposed(by: disposeBag)
}

AR Navigation Manager (WemapGeoARSDK)

To generate an itinerary and start navigation, you'll need to obtain an instance implementing ARNavigationManaging from GeoARView.

func startNavigation() {

let origin = Coordinate(latitude: 43.610628, longitude: 3.876654)
let destination = Coordinate(latitude: 43.609011, longitude: 3.917091)

let navigationOptions = NavigationOptions(stopWhenArrivedAtDestination: false) // NavigationOptions available for Map and AR SDKs
let searchRules: ItinerarySearchRules = .wheelchair // ItinerarySearchRules available for all SDKs

geoARView.navigationManager
.startNavigation(
origin: origin, destination: destination,
travelMode: .walk, // can be omitted because it's default mode
options: navigationOptions, searchRules: searchRules,
timeout: .seconds(10) // default value is .seconds(30)
)
.subscribe(
onSuccess: { _ in
debugPrint("Successfully started navigation from: \(origin) to: \(destination)")
},
onFailure: { error in
debugPrint("Failed to start navigation from \(origin) to: \(destination) with error: \(error)")
}
).disposed(by: disposeBag)
}

Itinerary Service (WemapCoreSDK)

To generate an itinerary, you'll need to obtain an instance implementing ItineraryServicing and request for itinerary computation using ItineraryParameters class.

Below are examples of how you can use specific options to compute itineraries for a few scenarios.

Compute itinerary

This example demonstrates how to calculate walking itineraries with origin and destination coordinates.

func computeItineraries() {

let origin = Coordinate(latitude: 43.610628, longitude: 3.876654)
let destination = Coordinate(latitude: 43.609011, longitude: 3.917091)

let parameters = ItineraryParameters(origin: origin, destination: destination) // default travelMode is .walk

ServiceFactory
.getItineraryService()
.itineraries(parameters: parameters)
.subscribe(
onSuccess: { response in
debugPrint("response - \(response)")
}, onFailure: {
debugPrint("error - \($0)")
}
)
.disposed(by: disposeBag)
}

You can specify travel mode and preference for the request:

func computeItineraries() {
...
let parameters = ItineraryParameters(
origin: origin, destination: destination, travelMode: .bike(preference: .safest)
)
...
}

Also is some cases you may need to specify search rules:

func computeItineraries() {
...
let parameters = ItineraryParameters(
origin: origin, destination: destination, travelMode: .walk, searchRules: .wheelchair
)
...
}

Examples

For additional examples and sample implementations of WemapSDKs, visit the official GitHub repository.

Clone the repository and follow the README instructions to run the sample application.