Navigation SDK is currently available only to select customers. Contact sales to learn more.

Customize your route

Stay organized with collections Save and categorize content based on your preferences.

When you are determining the best route for a ridesharing trip, the fastest route may not always be the best option. You may want to customize your route. The Routes Preferred API lets you customize a route by specifying a route objective using the ComputeCustomRoutes method.

When you create a custom route, the Routes Preferred API generates a route token. You can then pass the token to the Navigation SDK for iOS and retrieve the custom route.

For more information on creating a custom route, see Create Custom Routes.

Retrieving a custom route

You can retrieve a custom route by passing a route token to the Navigation SDK using the Navigator.setDestinations method, specifying the same destination waypoints that you gave to the Routes Preferred API.

When you pass the route token, the Navigation SDK ignores the following routing-related options:

  • travelMode
  • avoidsHighways
  • avoidsTolls
  • licensePlateRestriction

Waypoint-related options, such as the side-of-road preference, are not ignored. If the Navigation SDK has to adjust the returned route, it uses the options you specified to Routes Preferred API. For this reason, you should use the same waypoint-related options that you specified in Routes Preferred API.


The following code examples demonstrates how to retrieve a custom route.


let location = CLLocationCoordinate2D(latitude: 47.67, longitude: -122.20)
let waypoint1 = GMSNavigationWaypoint(location: location, title: "waypoint from location")!
let waypoint2 = GMSNavigationWaypoint(placeID: "samplePlaceID", title: "waypoint from Place ID")!

let routeToken = "route token returned by RoutesPreferred API"
mapView.navigator?.setDestinations([waypoint1, waypoint2], routeToken: routeToken, callback: {...})


CLLocationCoordinate2D location = CLLocationCoordinate2DMake(47.67, -122.20);
GMSNavigationWaypoint *waypoint1 = [[GMSNavigationWaypoint alloc] initWithLocation:coordinate title:@"waypoint from location"];
GMSNavigationWaypoint *waypoint2 = [[GMSNavigationWaypoint alloc] initWithPlaceID:@"samplePlaceID"
                                                                            title:@"waypoint from Place ID"];
NSString *routeToken = @"route token returned by RoutesPreferred API";

[mapView.navigator setDestinations:@[waypoint1, waypoint2]
                           callback:^(GMSRouteStatus routeStatus){...}];