iOS Native - Itineraries
The know the implemented features and the coverage please refers to the Routing API page
Itineraries
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 ItinerarySearchOptions
class to set a few search options.
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
.
private 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 searchOptions = ItinerarySearchOptions(avoidStairs: true) // ItinerarySearchOptions available for all SDKs
mapView.navigationManager
.startNavigation(
origin: origin,
destination: destination,
travelMode: .walk, // can be omitted because it's default mode
options: navigationOptions,
searchOptions: searchOptions,
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
.
private func getItinerariesForPreview() {
let origin = Coordinate(latitude: 43.610628, longitude: 3.876654)
let destination = Coordinate(latitude: 43.609011, longitude: 3.917091)
let searchOptions = ItinerarySearchOptions(avoidStairs: true) // ItinerarySearchOptions available for all SDKs
mapView.itineraryManager
.getItineraries(
origin: origin,
destination: destination,
travelMode: .walk, // can be omitted because it's default mode
searchOptions: searchOptions
)
.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
.
private 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 searchOptions = ItinerarySearchOptions(avoidStairs: true) // ItinerarySearchOptions available for all SDKs
geoARView.navigationManager
.startNavigation(
origin: origin,
destination: destination,
travelMode: .walk, // can be omitted because it's default mode
options: navigationOptions,
searchOptions: searchOptions,
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.
private 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: {
debugPrint("response - \($0)")
}, onFailure: {
debugPrint("error - \($0)")
}
)
.disposed(by: disposeBag)
}
You can specify travel mode and preference for the request:
private func computeItineraries() {
...
let parameters = ItineraryParameters(origin: origin, destination: destination, travelMode: .bike(preference: .safest))
...
}
Also is some cases you may need to specify search options:
private func computeItineraries() {
...
let parameters = ItineraryParameters(origin: origin, destination: destination, travelMode: .walk, searchOptions: .init(avoidStairs: true))
...
}
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.