管理航点

本文档介绍了如何使用以下两项功能管理应用的途经点偏好设置:

  • 道路一侧的路线偏好设置
  • 中途停留

设置靠哪侧行驶的路线偏好设置

默认情况下,iOS 版 Navigation SDK 会找到前往途经点的最快路线,但这并不能保证用户会到达道路的所需一侧,例如网约车司机的客户正在等待的那一侧。借助道路一侧的路线偏好功能,您可以确保车辆到达道路的正确一侧。

运作方式

您可以在为相应停靠点创建途经点时,设置到达道路特定一侧的偏好设置。您可以通过以下两种方式之一指定偏好设置。

首选同一侧道路

您提供途经点的地理坐标,然后设置一个标志 preferSameSideOfRoad,指示您希望在途经点所在的道路一侧(即贴靠到最近的人行道)到达。

(nullable instancetype)initWithLocation:(CLLocationCoordinate2D)location
                                  title:(NSString *)title
                   preferSameSideOfRoad:(BOOL)preferSameSideOfRoad;

设置到达航向

您提供途经点的地理坐标,然后提供与目的地同侧道路上的交通流方向一致的到达航向 preferredSegmentHeading

(nullable instancetype)initWithLocation:(CLLocationCoordinate2D)location
                                  title:(NSString *)title
                preferredSegmentHeading:(int32_t)preferredSegmentHeading;

Navigation SDK 会选择最靠近航点且车道方向与航点所在道路一侧方向一致(相差不超过 +/- 55 度)的路段。

设置中途停留偏好

在某些地方,用户无法安全停车(例如,高架区域、渡轮、地下位置和其他限制进入的区域)。如果途经点的位置不适合用户停留,途经点功能会将该途经点重新定位到附近的位置。如果您将 vehicleStopover 设置为 YES,系统会在计算路线时自动重新定位航点(如果存在替代位置)。

运作方式

您可以在为经停点创建途经点时设置经停偏好设置。 为此,请在 GMSNavigationMutableWaypoint 上设置经停的偏好设置,如以下示例所示:

Swift

let location = CLLocationCoordinate2D(latitude: 47.67, longitude: -122.20)
let waypoint = GMSNavigationMutableWaypoint(location: location, title: "waypoint from location")!
waypoint.vehicleStopover = true
mapView.navigator?.setDestinations([waypoint], routingOptions: routingOptions, callback: {...})

Objective-C

CLLocationCoordinate2D location = CLLocationCoordinate2DMake(47.67, -122.20);
GMSNavigationMutableWaypoint *waypoint =
    [[GMSNavigationMutableWaypoint alloc] initWithLocation:location
                                                     title:@"waypoint from location"];
waypoint.vehicleStopover = YES;
[_mapView.navigator setDestinations:@[waypoint1]
                     routingOptions:routingOptions
                           callback:^(GMSRouteStatus routeStatus){...}];