自定义导航体验
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Navigation SDK 提供了多种将导航体验集成到应用中的方式。本页将介绍什么是自定义导航体验,以及它与 Navigation SDK 中提供的其他导航体验有何不同。
什么是自定义导航体验?
实现 Navigation SDK 的主要方式是使用 Google 导航体验,这样您就可以嵌入使用 Google 提供的界面元素和视觉效果的精细导航体验,类似于 Google 地图应用中的导航体验。如果您需要比 Google 导航体验更灵活的体验,可以实现自定义导航体验。自定义导航体验是指各种各样的体验,从完全不提供转弯指引,仅在后台进程中运行导航,到将高度自定义的指引体验投影到运行导航的设备以外的屏幕上,应有尽有。借助自定义导航体验,您的应用会调用 Navigation SDK 来请求逐向导航 Feed,然后您提供并管理用户在导航体验中看到的界面元素和视觉效果。虽然使用 Google 导航体验通常更容易实现,但构建自己的自定义导航体验可以实现更多自定义。
创建自定义导航体验时,您的应用会调用 Navigation SDK 来启动、运行和停止导航,具体流程如下:
开始导航。与 Google 导航体验一样,自定义导航体验仍然需要创建导航实例并设置目的地。不过,借助自定义导航体验,您可以通过以下方式实现此目的:首先使用 GMSNavigationService.createNavigationSession
建立导航会话,GMSNavigationService.createNavigationSession
是一个有状态的非界面对象,可以与视图控制器一起运行,也可以单独运行。
如需了解详情,请参阅有关逐向导航数据 Feed 的详细信息。
查看演示:下载的 Navigation SDK 包含一个演示,您可以运行该演示来查看导航体验示例。该示例会在标准导航的逐向引导与仅显示设备位置沿道路折线移动的导航体验之间切换。
有效导航。以下是 Google 提供的导航体验与自定义导航体验之间的另一个主要区别。
您无需将指导信息交给 Navigation SDK 的内置事件管理器,而是通过实现 GMSNavigatorListener
协议来设置详细的逐向转弯指导信息的监听器,然后实现事件处理程序。这样一来,您的体验就可以响应监听导航事件中所述的事件。
结束导航。与 Google 导航体验一样,自定义导航也要求您以最适合应用体验的方式终止导航。
您可以在什么情况下使用自定义导航体验?
下表介绍了一些自定义导航场景。
示例场景 |
简要步骤 |
您需要为小型设备(例如两轮车辆)提供纯文字的驾驶指导。 |
创建导航器并将精细导航设置为数据源,以提供给小屏幕设备,同时导航器在驾驶员的手机上运行,但不在驾驶员的直接视野范围内。 |
您希望将应用作为汽车服务提供给使用 Apple CarPlay 的驾驶员。 |
- 设置汽车服务。
- 设置 Navigation SDK 项目。
- 如果您尚未建立导航员,请建立一个。
- 为精细导航设置监听器。
- 在 Android Auto 应用界面上绘制地图,并使用您配置的数据 Feed 填充字段。
如需了解详情,请参阅为 CarPlay 启用导航 |
使用您应用的司机希望在大部分行程中使用概览地图,仅在城市街道上使用最少的精细导航。 |
您的应用应允许司机根据需要进入和退出 Google 导航体验,而无需交替更改导航器的目的地和行程模式设置。 |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Navigation SDK offers a custom navigation experience for greater flexibility beyond the standard Google navigation experience.\u003c/p\u003e\n"],["\u003cp\u003eCustom navigation involves managing UI elements and visuals, starting navigation sessions, listening for events, and ending navigation.\u003c/p\u003e\n"],["\u003cp\u003eCustom experiences are suitable for scenarios like text-only guidance, Carplay integration, or combining overview maps with minimal turn-by-turn guidance.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can access the turn-by-turn data feed and detailed navigation events to create highly customized navigation interfaces.\u003c/p\u003e\n"]]],[],null,["# Custom navigation experience\n\nThe Navigation SDK provides different ways to integrate a navigation\nexperience into your app. This page explains what a custom navigation experience\nis and how it differs from other navigation experiences that are available in\nthe Navigation SDK.\n\nWhat is a custom navigation experience?\n---------------------------------------\n\nThe primary way to implement the Navigation SDK is to use the [Google\nnavigation\nexperience](/maps/documentation/navigation/ios-sdk/intro-google-nav),\nwhich lets you embed a turn-by-turn navigation experience that uses\nGoogle-provided UI elements and visuals --- similar to the navigation experience\nwithin the Google Maps apps. If you need more flexibility than the Google\nnavigation experience offers, you can implement a custom navigation experience.\nA custom navigation experience refers to anything from eliminating turn guidance\nentirely with and running navigation only as a background process, to projecting\na highly customized guidance experience to a screen separate from the device\nthat runs the navigation. With a custom navigation experience, your app calls\nthe Navigation SDK to request a turn-by-turn navigation feed, and then\nyou provide and manage the UI elements and visuals that the user sees in the\nnavigation experience. While using the Google navigation experience is generally\neasier to implement, building your own custom navigation experience allows for\nmore customization.\n\nWhen you create a custom navigation experience, your app calls the Navigation\nSDK to start, run, and stop navigation, using the following flow:\n\n1. **Start navigation** . As with the Google navigation experience, a custom\n navigation experience still involves creating a navigation instance and\n setting the destination. However, with a customized navigation experience,\n you achieve this by first establishing a navigation session using\n `GMSNavigationService.createNavigationSession`, which is a state-bearing\n non-UI object that can operate either with a view controller, or without\n one.\n\n \u003cbr /\u003e\n\n For more information, see [Details about the turn-by-turn data\n feed](/maps/documentation/navigation/ios-sdk/nav-only-feed).\n\n **See the demo:** The download of the Navigation SDK contains a demo\n you can run to see an example of a navigation experience that switches\n between turn-by-turn guidance through standard navigation to a navigation\n experience that shows only the device location moving along a road\n polyline.\n2. **Active navigation** . Here is another key difference between a\n Google-provided navigation experience and a custom navigation experience.\n Instead of handing off guidance to the built-in event manager of the\n Navigation SDK, you set up a listener for detailed turn-by-turn guidance by implementing the `GMSNavigatorListener` protocol, and then implement event\n handlers. This allows your experience to respond to the events described in\n [Listen for navigation\n events](/maps/documentation/navigation/ios-sdk/events).\n\n3. **End navigation**. As with the Google navigation experience, custom\n navigation also requires you to terminate navigation in the manner best\n suited for the app's experience.\n\nWhen might you use a custom navigation experience?\n--------------------------------------------------\n\nThe following table describes some custom navigation scenarios.\n\n| **Example scenario** | **High-level steps** |\n|----------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| You need to provide text-only driver guidance for small devices such as 2-wheeled vehicles. | Create your navigator and set up the turn-by-turn guidance as a data feed to a small screen device while the navigator runs on the driver's mobile phone outside of their immediate view. |\n| You want to make your app available as a car service for drivers who use Apple Carplay. | 1. Set up the car service. 2. Set up your Navigation SDK project. 3. Establish a navigator if you haven't already. 4. Set up a listener for turn-by-turn guidance. 5. Draw the map on the auto app surface and populate the fields from the data feed you configured. For more information, see [Enable Navigation for Carplay](/maps/documentation/navigation/ios-sdk/carplay) |\n| Drivers using your app want an overview map for most of their journey, with only minimal turn-by-turn guidance for city streets. | Your app should allow drivers to enter and exit the Google navigation experience as they need, without alternating the navigator's settings for destination and trip mode. |"]]