管理路線控點

本文件說明如何使用兩項功能來管理應用程式的路線控點偏好設定:

  • 路線規劃偏好設定的側邊
  • 停靠點

設定道路路線偏好設定的側邊

根據預設,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){...}];