Car and Pedestrian Routing

The Sygic iOS SDK supports route calculation with multiple waypoints, optimized for walking or driving. A route describes a path between at least two waypoints, the starting point and the destination, with optional intermediate waypoints in between.

Applications can provide route information to users in two ways:

  • A line rendered on a map that displays a connecting path between all waypoints
  • Turn-by-turn directions in text format

SYRoutingOptions
Represents the routing options (represented by the SYRoutingOption enums) that are applicable for the selected route

SYTransportmode property of SYRoutingOptions class provides following modes of routing:

  • Car
  • Pedestrian
  • Public Transport
  • Unknown

Following example shows how to calculate the route from startpoint to endpoint and start the navigation.

class RoutingViewController: UIViewController, SYRoutingDelegate {
    let mapView = SYMapView()

    func computeRoute(from fromCoordinate: SYGeoCoordinate, to toCoordinate: SYGeoCoordinate) {
        // Create an instance of SYRouting
        let routing = SYRouting()

        // Make self a delegate for SYRouting to receive and handle SYRoutingDelegate responses
        routing.delegate = self

        // Create SYWaypoint from coordinate. Set correct SYWaypointType for start and finish.
        let startWaypoint = SYWaypoint(position: fromCoordinate, type: .start, name: nil)
        let endWaypoint = SYWaypoint(position: toCoordinate, type: .end, name: nil)

        // Optionally: create an instance of SYRoutingOptions for configuring computing of a route
        let routingOptions = SYRoutingOptions()
        routingOptions.transportMode = .car // For other options see SYTransportMode
        routingOptions.routingType = .fastest // For other options see SYRoutingType

        // Start computing route
        routing.computeRoute(startWaypoint, to: endWaypoint, via: nil, with: routingOptions)
    }

    // MARK: - SYRoutingDelegate

    func routing(_ routing: SYRouting, didComputePrimaryRoute route: SYRoute?, withError error: SYRoutingError) {
        // if you want to start the navigation with this route
        SYNavigation.shared().start(with: route)

        // You might want to put it also on the map

        let mapRoute = SYMapRoute(route: route, type: .primary)
        mapView.add(SYMapRoute(route: route, type: .primary))
    }
}

SYWaypoint

You can use SYWaypoint to add waypoint(s) details to a car route calculation.

// Create SYWaypoint with type .via
let waypoint = SYWaypoint(position: fromCoordinate, type: .via, name: nil)

// Pass it to SYRouting. Other parts remains.
routing.computeRoute(startWaypoint, to: endWaypoint, via: [waypoint], with: routingOptions)

Route Serialization

Route serialization is a feature that allows users to use the new SYRoute method serializeRoute: to serialize a route into NSData, which can then be saved as a file. This is useful when a user would like to recover from a crash during navigation or when a user would like to transfer a route from one device to another.

The following is an example of how to invoke the serialization APIs:

// Serialization
let serializer = SYRouteSerializerBrief()
let jsonSerializedRoute = serializer.serializeRoute(route)

// Computing route from json
routing.computeRoute(fromJson: jsonSerializedRoute)