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: UIController, SYRoutingDelegate {
    let mapView: SYMapView

    func computeRoute(from fromCoordinate: SYGeoCoordinate, to toCoordinate: SYGeoCoordinate) {
        let routing = SYRouting()
        routing.delegate = self

        // get these from user tapping on the map or from the search
        let startWaypoint = SYWaypoint(position: fromCoordinate, type: .start)
        let endWaypoint = SYWaypoint(position: toCoordinate, type: .end)

        let routingOptions = SYRoutingOptions()
        routingOptions.transportMode = .car // or choose whichever you want
        routing.computeRoute(startWaypoint, to: endWaypoint, via: [], 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)

        // and you might want to put it also on the map
        mapView.add(SYMapRoute(route: route, type: .primary))
    }
}

SYWaypoint

You can use SYWaypoint to add waypoint(s) details to a car route calculation. These details include whether a waypoint is a deliberate stopover or a via point that the route must pass through. This affects routing, as routes containing stopovers or via waypoints may be different. For example, a calculated route may suggest a U-turn maneuver after a stopover, while a route containing the same location as a via waypoint suggests continuing on the same street. The via waypoint type is only supported in car routes, and it is not supported in other route types.

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)