為指定 Android 的 Unity (AR Foundation) 應用程式啟用地理空間 API
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
設定應用程式,讓應用程式能夠使用 Geospatial API。
必要條件
請務必先瞭解基本 AR 概念,並瞭解如何設定 ARCore 工作階段,再繼續操作。
如要進一步瞭解 Geospatial API,請參閱「Geospatial API 簡介」。
如果您是 ARCore 開發新手,請參閱「開發入門」一文,瞭解軟體和硬體需求、前置條件,以及其他特定平台的相關資訊。
如要使用 ARCore Geospatial API,您的專案必須支援 AR Foundation 和 ARCore 擴充功能。
啟用 ARCore API
在應用程式中使用視覺定位系統 (VPS) 前,您必須先在新的或現有 Google Cloud 專案中啟用 ARCore API。這項服務負責代管、儲存及解析地理空間錨點。
建議使用無金鑰授權,但也支援 API 金鑰授權。
將必要的程式庫新增至應用程式
授權應用程式呼叫 ARCore API 後,您必須新增程式庫,才能在應用程式中啟用地理空間功能。
- 依序前往「Edit」 >「Project Settings」 >「XR Plug-in Management」 >「ARCore Extensions」。
- 在「選用功能」下方,選取「地理空間」。

在工作階段設定中啟用地理空間功能
在應用程式中啟用 Geospatial 功能後,請在應用程式的 AR 工作階段設定中啟用 Geospatial 功能,以便與 ARCore API 通訊:
- 請確認專案的 Assets 資料夾包含可編寫指令碼的 ARCoreExtensionsConfig 物件。如要建立這項資源,請在「Assets」窗格中按一下滑鼠右鍵,然後依序選取「Create」 >「XR」 >「ARCore Extensions Config」。
在「Assets」資料夾中選取「ARCoreExtensionsConfig」可編碼物件,然後將「Geospatial Mode」設為「Enabled」。

設定 ARCore Extensions 遊戲物件,以便使用 ARCoreExtensionsConfig 設定。在「層級」窗格中,找出您在初始設定 ARCore 擴充功能時建立的「ARCore Extensions」遊戲物件,然後將「ARCore Extensions Config」欄位連結至「Assets」資料夾中的「ARCoreExtensionsConfig」可編寫指令碼的物件。

提示使用者允許使用裝置資料
使用 ARCore Geospatial API 的應用程式必須向使用者顯示提示,讓使用者確認並允許使用裝置資料。詳情請參閱「使用者隱私權規定」。
檢查裝置相容性
並非所有支援 ARCore 的裝置都支援 Geospatial API。如要檢查使用者的裝置相容性,請呼叫 AREarthManager.IsGeospatialModeSupported()
。如果傳回 FeatureSupported.Unsupported
,請勿嘗試設定工作階段。
在執行階段要求使用者提供位置存取權
在 ARCoreExtensions.Update()
中啟用地理空間模式時,ARCore 擴充功能會自動要求適當的位置資訊權限。如果使用者未授予精確位置權限,工作階段將無法繼續,並顯示「未授予權限」錯誤。這是終止錯誤,需要重新啟動才能再次觸發權限要求。
查看裝置目前位置的 Geospatial 供應情形
由於 Geospatial API 會結合 VPS 和 GPS 來判斷地理空間姿勢,因此只要裝置能夠判斷自身位置,即可使用此 API。在 GPS 精確度較低的區域 (例如室內空間和擁擠的都會環境),API 會依靠 VPS 涵蓋範圍產生高精確度姿勢。在一般情況下,VPS 可提供約 5 公尺的位置精確度,以及 5 度的旋轉精確度。使用 AREarthManager.CheckVpsAvailability()
判斷特定位置是否有 VPS 涵蓋範圍。
地理空間 API 也適用於未涵蓋 VPS 的區域。在沒有或幾乎沒有上方遮蔽物的室外環境中,GPS 可能就足以產生高精確度的姿勢。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-14 (世界標準時間)。
[null,null,["上次更新時間:2025-07-14 (世界標準時間)。"],[[["\u003cp\u003eConfigure your app to utilize the Geospatial API by enabling the ARCore API in a Google Cloud project and adding necessary libraries.\u003c/p\u003e\n"],["\u003cp\u003eEnable Geospatial capabilities within your app's AR session configuration using the ARCoreExtensionsConfig scriptable object.\u003c/p\u003e\n"],["\u003cp\u003eEnsure user privacy by prompting users to allow usage of device data and requesting location permissions at runtime.\u003c/p\u003e\n"],["\u003cp\u003eVerify device and location compatibility by checking Geospatial API support and VPS availability before utilizing Geospatial features.\u003c/p\u003e\n"],["\u003cp\u003eAfter setup, you can obtain the device's Geospatial pose and check VPS availability for specific locations.\u003c/p\u003e\n"]]],[],null,["# Enable the Geospatial API for your Unity (AR Foundation) app targeting Android\n\nConfigure your app's settings so that it can use the [Geospatial API](/ar/develop/geospatial).\n\nPrerequisites\n-------------\n\nMake sure that you understand [fundamental AR concepts](/ar/develop/fundamentals)\nand how to [configure an ARCore session](/ar/develop/unity-arf/session-config) before proceeding.\n\nSee the\n[Introduction to the Geospatial API](/ar/develop/geospatial) for more\ninformation about the Geospatial API.\n\nIf you're new to developing with ARCore, see [Getting started](/ar/develop/getting-started)\nfor information about software and hardware requirements, prerequisities and\nother information specific to the platforms you are using.\n\nTo use the ARCore Geospatial API, your project must support\n[AR Foundation](/ar/develop/unity-arf/getting-started-ar-foundation#requirements)\nand the [ARCore Extensions for AR Foundation](/ar/develop/unity-arf/getting-started-extensions).\n\nEnable the ARCore API\n---------------------\n\nBefore using the Visual Positioning System (VPS) in your app, you must first\nenable the [**ARCore API**](/ar/develop/authorization?platform=unity-arf-android)\nin a new or existing Google Cloud project. This service is responsible for\nhosting, storing, and resolving Geospatial anchors.\n\nKeyless authorization is preferred, but API Key authorization is also supported.\n\nAdd required libraries to your app\n----------------------------------\n\nAfter authorizing your app to call the ARCore API, you must add libraries to\nenable Geospatial features in your app.\n\n1. Navigate to **Edit** \\\u003e **Project Settings** \\\u003e **XR Plug-In Management** \\\u003e **ARCore Extensions**.\n2. Under **Optional Features** , select **Geospatial**.\n\nEnable Geospatial capabilities in the session configuration\n-----------------------------------------------------------\n\nOnce Geospatial functionality has been enabled in your app, enable Geospatial capabilities in your app's [AR session configuration](/ar/develop/unity-arf/session-config) so that it can communicate with the ARCore API:\n\n1. Ensure that the project **Assets** folder contains an **ARCoreExtensionsConfig** scriptable object. To create one, right-click in the **Assets** pane and select **Create** \\\u003e **XR** \\\u003e **ARCore Extensions Config**.\n2. Select the **ARCoreExtensionsConfig** scriptable object in your **Assets** folder and set the **Geospatial Mode** to **Enabled**.\n\n3. Configure the **ARCore Extensions** game object to use the **ARCoreExtensionsConfig** configuration. In the **Hierarchy** pane, locate the **ARCore Extensions** game object you created when you initially set up ARCore Extensions, and connect the **ARCore Extensions Config** field to the **ARCoreExtensionsConfig** scriptable object in your **Assets** folder.\n\nPrompt user to allow usage of device data\n-----------------------------------------\n\nApps that use the ARCore Geospatial API must present the user with a prompt to\nacknowledge and allow the use of data from their device. See\n[User privacy requirements](/ar/develop/privacy-requirements) for more\ninformation.\n\nCheck device compatibility\n--------------------------\n\nNot all devices that support ARCore also support the Geospatial API. To check\nthe user's device for compatibility, call\n[`AREarthManager.IsGeospatialModeSupported()`](/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/AREarthManager#isgeospatialmodesupported).\nIf this returns `FeatureSupported.Unsupported` do not attempt to configure the\nsession.\n\nAsk user for location permissions at runtime\n--------------------------------------------\n\nARCore Extensions automatically requests the appropriate location permissions\nwhen Geospatial mode is enabled in `ARCoreExtensions.Update()`. If the user does\nnot grant precise location permission, the session fails to resume, and a\n\"permission not granted\" error is produced. This is a terminate\nerror, and requires a re-start to trigger the permission request again.\n\nCheck Geospatial availability at the device's current location\n--------------------------------------------------------------\n\nBecause the Geospatial API uses a combination of [VPS](/ar/develop/geospatial#global_localization_with_vps) and GPS to determine a Geospatial pose, the API can be used as long as the device is able to determine its location. In areas with low GPS accuracy, such as indoor spaces and dense urban environments, the API will rely on VPS coverage to generate high accuracy poses. Under typical conditions, VPS can be expected to provide positional accuracy of approximately 5 meters, and rotational accuracy of 5 degrees. Use [`AREarthManager.CheckVpsAvailability()`](/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/AREarthManager#checkvpsavailability) to determine if a given location has VPS coverage.\n\nThe Geospatial API can also be used in areas that do not have VPS coverage. In outdoor environments with few or no overhead obstructions, GPS may be sufficient to generate a pose with high accuracy.\n\nWhat's next\n-----------\n\n- [Obtain the device camera's Geospatial pose](/ar/develop/unity-arf/geospatial/obtain-device-pose) to determine the exact location of the user's device in the real world.\n- [Check VPS availability](/ar/develop/unity-arf/geospatial/check-vps-availability) at a device's given location."]]