本文說明如何使用下列兩項功能,管理應用程式的航點偏好設定:
- 道路兩側的路線偏好設定
- 中途停留
設定道路兩側的路線偏好設定
根據預設,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){...}];