Itinerary Service
The itineraries used in the WemapMapSDK
are generated by the Wemap Routing API. When you install the WemapMapSDK
, it also includes WemapCoreSDK
which has ItineraryServicing
protocol, which provides a convenient way to access the Wemap Routing API.
To generate an itinerary, you’ll need to obtain an instance implementing ItineraryServicing
and request for itinerary computation using ItineraryParameters
class. You also can use the ItinerarySearchOptions
class to set a few 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
.
Below are examples of how you can use specific options to compute itineraries for a few scenarios.
The code examples below show how to use the
WemapCoreSDK
without theWemapMapSDK
, but if you useWemapMapSDK
- this logic is managed byItineraryManager
andMapNavigationManaging
ofWemapMapSDK
.
Compute itinerary
This example demonstrates how to calculate walking itineraries with origin and destination coordinates.
import RxCocoa
import RxSwift
import UIKit
import WemapCoreSDK
class ViewController: UIViewController {
private let disposeBag = DisposeBag()
private let service = ServiceFactory.getItineraryService()
override func viewDidLoad() {
super.viewDidLoad()
computeItineraries()
}
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
service
.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
You can find additional examples for the WemapSDKs on GitHub. Clone the repository and run the example application following the instructions in the README.