前往导航点

Navigation SDK for iOS 提供了增强的指定途经点的方式,可实现更准确的路线规划和更好的到达体验,尤其是在目的地有多个入口或特定接入点的情况下。您可以使用 navigationPointToken 或将位置坐标与地点 ID 相结合,以提供更多背景信息,从而规划前往精确位置的路线。

如果适用,系统将继续执行目的地突出显示功能。

背景

在 v10.10 之前,您可以使用位置坐标地点 ID 定义 Waypoint。虽然有时有效,但仅根据纬度和经度规划路线有时会导致下车点或上车点不尽理想,尤其是在大型场所、公园或有多个入口的建筑物中。结果可能会贴靠到最近的路段,但该路段可能不是最方便或最正确的入口点。

增强型途经点选项允许您提供更多背景信息,从而解决此问题。

使用导航点令牌

如需获得前往特定接入点(例如入口、装货平台或指定取货区)的最精确路线,您可以使用 navigationPointToken

此令牌通过调用 Geocoding API 的 Destinations 方法获得。它表示与某个地点关联的特定可路由导航点。

如需指定导航点令牌,请执行以下操作:

  1. Geocoding API 的 Destinations 方法响应中获取 navigationPointToken

  2. 创建 GMSNavigationWaypoint 时,请指定 navigationPointToken

注意:您无法同时指定导航点令牌以及位置和 PlaceID。

Swift

// Create a waypoint using a navigation endpoint token
let waypointTwo = GMSNavigationWaypoint(
  navigationPointToken: "ChIJALijSXPhQkARHmIozCCbXsASEgkFVjYHGH6PgBFrbM7wl3.."
  title: "Sydney Opera House")

// Route to the waypoint
navigator.setDestinations([waypointTwo]) { [weak self] routeStatus in
   self?.handleRouteCallback(status: routeStatus)
}

Objective-C

GMSNavigationWaypoint *waypointTwo = [[GMSNavigationWaypoint alloc] initWithNavigationPointToek:@"sampleNavigationPointToken"

结合使用地点 ID 和位置信息

从 v10.10 开始,您可以在创建途经点时同时提供地点 ID 和位置坐标。如果您想指定一个精确的点(位置),同时仍提供整个地点的上下文(地点 ID),此方法会很有用。这样,Navigation SDK 就能通过突出显示目的地建筑物或显示与地点 ID 相关的附近兴趣点,提供更丰富的到达体验。

Swift

// Create a waypoint using both the latlng and placeID
let waypoint = GMSNavigationWaypoint(
  location: CLLocationCoordinate2DMake(-33.85657945261524, 151.21535034203333),  
  placeID: "ChIJ3S-JXmauEmsRUcIaWtf4MzE",
  title: "Sydney Opera House")

// Route to the waypoint
navigator.setDestinations([waypoint]) { [weak self] routeStatus in
   self?.handleRouteCallback(status: routeStatus)
}

Objective-C

CLLocationCoordinate2D location = CLLocationCoordinate2DMake(47.67, -122.20);
GMSNavigationWaypoint *waypoint = [[GMSNavigationWaypoint alloc] initWithLocation:placeID:coordinate title:@"waypoint from location and placeiD"];

注意事项:

如果您同时提供 placeIDlocation

  • 相应路线主要面向指定的 location
  • placeId 用作上下文,以提升到达体验。
  • 回退:如果 SDK 确定所提供的 placeId 对应的功能与给定的 location 相差太远,则会忽略 placeId。在这种情况下,系统只会继续前往 location,而不会提供特定地点的到达体验增强功能。

有效航点配置摘要

规范 location placeID navigationPointToken 路由行为 突出显示目的地
仅限位置坐标 set 缺席 缺席 前往距离指定坐标最近的路段的路线 如果系统能以较高置信度推断出目的地,则显示此字段
仅限地点 ID 缺席 set 缺席 前往相应地点 ID 的默认导航点的路线 出发地地点 ID
仅限导航点令牌 缺席 缺席 set 前往令牌所表示的精确导航点的路线 来自 Geocoding API 的 destinations 方法请求中定义的目的地
位置坐标和地点 ID 组合 se set 缺席 前往距离指定坐标最近的路段的路线 来自地点 ID,但如果地点 ID 与纬度/经度坐标相距太远,则不会显示