自訂導覽體驗
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Navigation SDK 提供多種方式,可將導航體驗整合至應用程式。本頁說明自訂導航體驗,以及與 Navigation SDK 中其他導航體驗的不同之處。
什麼是自訂導覽體驗?
實作 Navigation SDK 的主要方式是使用 Google 導航體驗,這項體驗可讓您嵌入使用 Google 提供 UI 元素和視覺效果的行車路線導航體驗,類似於 Google 地圖應用程式中的導航體驗。如果需要比 Google 導覽體驗更靈活的導覽方式,可以實作自訂導覽體驗。自訂導覽體驗是指任何導覽方式,包括完全取消轉彎指引,只在背景執行導覽,或是將高度自訂的指引體驗投放到執行導覽的裝置以外的螢幕。透過自訂導覽體驗,應用程式會呼叫 Navigation SDK,要求提供逐步導覽動態饋給,然後您提供及管理使用者在導覽體驗中看到的 UI 元素和視覺效果。雖然使用 Google 導覽體驗通常較容易實作,但自行建構自訂導覽體驗可提供更多自訂選項。
建立自訂導航體驗時,應用程式會呼叫 Navigation SDK,按照下列流程啟動、執行及停止導航:
開始導航。與 Google 導覽體驗相同,自訂導覽體驗仍須建立導覽執行個體並設定目的地。不過,如果採用自訂導覽體驗,您首先要使用 GMSNavigationService.createNavigationSession
建立導覽工作階段,這是具有狀態的非 UI 物件,可搭配或不搭配檢視畫面控制器運作。
詳情請參閱「詳細瞭解逐向導航資料動態饋給」。
查看試用版:下載 Navigation SDK 後,您會看到一個試用版,執行後即可查看導航體驗範例,瞭解如何從標準導航的逐步導引,切換為只顯示裝置位置沿著道路折線移動的導航體驗。
啟用導覽。以下是 Google 提供的導覽體驗與自訂導覽體驗的另一項主要差異。您不必將指引交給 Navigation SDK 的內建事件管理工具,而是實作 GMSNavigatorListener
協定來設定詳細的轉彎指引監聽器,然後實作事件處理常式。這樣一來,您的體驗就能回應「監聽導覽事件」一節所述的事件。
結束導航。與 Google 導覽體驗相同,自訂導覽也需要您以最適合應用程式體驗的方式終止導覽。
何時會使用自訂導覽體驗?
下表說明一些自訂導覽情境。
範例情境 |
步驟概覽 |
您必須為小型裝置 (例如雙輪車輛) 提供僅含文字的駕駛指引。 |
建立導航員,並將即時路線導航設為資料動態饋給,傳送至小型螢幕裝置。導航員則在駕駛人手機上執行,但駕駛人無法直接看到。 |
您希望應用程式能做為車輛服務,供使用 Apple CarPlay 的駕駛人使用。 |
- 設定車輛服務。
- 設定 Navigation SDK 專案。
- 如果尚未建立導覽器,請先建立。
- 設定即時路線指引的監聽器。
- 在 Android Auto 應用程式介面上繪製地圖,並從您設定的資料動態饋給填入欄位。
詳情請參閱「為 CarPlay 啟用導航功能」。 |
使用您應用程式的駕駛人希望在大部分的旅程中查看總覽地圖,只有在市區街道才需要最少的行車路線導航指引。 |
應用程式應允許駕駛人視需要進入和退出 Google 導航體驗,而不必交替設定導航器的目的地和行程模式。 |
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間: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. |"]]