管理航点

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

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

设置道路一侧路线偏好

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

运作方式

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

首选道路同侧

您需要提供航点的地理坐标,然后设置一个标志 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 度范围内)。

设置中途停留偏好

在某些地方,用户无法安全停车(例如,高架区域、渡轮、地下位置和其他出入受限的区域)。如果航点的位置不适合用户停留,Stopover 功能会将航点重新定位到附近的地点。如果您将 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){...}];