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.

Example

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

Swift

CLLocationCoordinate2D location = CLLocationCoordinate2D(47.67, -122.20);
GMSNavigationWaypoint *waypoint1 = GMSNavigationWaypoint(withLocation: location,
                                                         title: @"waypoint from location");
GMSNavigationWaypoint *waypoint2 = GMSNavigationWaypoint(withPlaceID: @"samplePlaceID",
                                                         title: @"waypoint from Place ID");

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

Objective-C

GMSNavigationWaypoint *waypoint2 = [[GMSNavigationWaypoint alloc] initWithPlaceID:@"samplePlaceID"
                                                                            title:@"waypoint from Place ID"];
NSString *routeToken = @"route token returned by RoutesPreferred API";

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