檢查裝置的 VPS 可用性';目前位置
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Geospatial API 會結合 VPS 和 GPS 資料,產生高精確度的地理空間姿勢。只要裝置能夠判斷自身位置,這個 API 就能在任何地方使用:
- 在 GPS 精確度較低的區域 (例如室內空間和擁擠的都會環境),API 會依靠 VPS 涵蓋範圍產生高精確度姿勢。
- 在沒有或幾乎沒有上方遮蔽物的戶外環境中,Geospatial API 可能可以使用可用的 GPS 位置資料,產生高精確度的地理空間姿勢。
您可以在 AR 工作階段開始前,判斷特定水平位置的 VPS 可用性,並利用這項資訊打造更具體的體驗,例如只在 VPS 可用時顯示「進入 AR」按鈕。
啟用 ARCore API
應用程式必須啟用 ARCore API,才能檢查 VPS 是否可用。
檢查應用程式中的 VPS 供應情形
只要裝置能夠判斷自身位置,Geospatial API 就能在任何地方使用。如果 AR 體驗取決於 VPS 涵蓋範圍,您可以使用 AREarthManager.CheckVpsAvailabilityAsync()
取得 VpsAvailabilityPromise
,這是一個非同步工作,可檢查特定水平位置的 VPS 可用性。取得 VpsAvailabilityPromise
後,您可以透過輪詢取得結果。
輪詢結果
使用 VpsAvailabilityPromise.State
取得 InterruptiblePromise
的狀態。狀態共有三種:
您可以繼續檢查 VpsAvailabilityPromise.State
,直到工作完成為止。
取消 InterruptiblePromise
使用 VpsAvailabilityPromise.Cancel()
嘗試取消 InterruptiblePromise
。由於執行緒並行,取消嘗試可能實際上並未成功。
在沒有 VPS 涵蓋範圍的情況下使用 Geospatial API
地理空間 API 也適用於未涵蓋 VPS 的區域。在沒有或幾乎沒有上方遮蔽物的室外環境中,GPS 可能就足以產生高精確度的姿勢。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-14 (世界標準時間)。
[null,null,["上次更新時間:2025-07-14 (世界標準時間)。"],[[["\u003cp\u003eThe Geospatial API leverages VPS and GPS data to create highly accurate location anchors, enabling augmented reality experiences in diverse environments.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can check VPS availability before an AR session begins, optimizing user experience by prompting interactions only when VPS is available.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eAREarthManager.CheckVpsAvailabilityAsync()\u003c/code\u003e allows developers to determine VPS availability at a specific location, which can be polled for its status and potentially cancelled.\u003c/p\u003e\n"],["\u003cp\u003eEven without VPS coverage, the Geospatial API can utilize GPS data in outdoor settings with clear skies to achieve accurate pose estimation.\u003c/p\u003e\n"],["\u003cp\u003eAfter confirming VPS availability or GPS suitability, developers can proceed to obtain the device's Geospatial pose, anchoring AR content to real-world locations.\u003c/p\u003e\n"]]],[],null,["# Check VPS availability at the device's current location\n\n\u003cbr /\u003e\n\nThe Geospatial API uses a combination of [VPS](/ar/develop/geospatial#global_localization_with_vps) and GPS data to generate high-accuracy Geospatial poses. The API can be used in any place where the device is able to determine its location:\n\n- 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.\n- In outdoor environments with few or no overhead obstructions, the Geospatial API may be able to use available GPS location data to generate Geospatial poses with high accuracy.\n\nYou can determine VPS availability at a given horizontal position before the AR session starts and use it to create more specific experiences --- for example, to present an \"Enter AR\" button only when VPS is available.\n\nEnable the ARCore API\n---------------------\n\nYour app must enable the [ARCore API](/ar/develop/unity-arf/geospatial/enable#enable_the_arcore_api) to check VPS availability.\n\nCheck VPS availability in your app\n----------------------------------\n\nThe Geospatial API can be used in any place where the device is able to determine its location. If your AR experience hinges on VPS coverage, you can use [`AREarthManager.CheckVpsAvailabilityAsync()`](/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/AREarthManager#checkvpsavailabilityasync) to obtain a [`VpsAvailabilityPromise`](/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/VpsAvailabilityPromise), an asynchronous task that checks the VPS availability at a given horizontal position.\n\nOnce you have the [`VpsAvailabilityPromise`](/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/VpsAvailabilityPromise), you can obtain its result by polling.\n\n\n### Poll the result\n\nUse [`VpsAvailabilityPromise.State`](/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/VpsAvailabilityPromise#state) to obtain the state of the `InterruptiblePromise`. There are three different states:\n\n- [`Pending`](/ar/reference/unity-arf/namespace/Google/XR/ARCoreExtensions#promisestate): The operation is not yet complete, so no result is known.\n- [`Cancelled`](/ar/reference/unity-arf/namespace/Google/XR/ARCoreExtensions#promisestate): The operation has been cancelled by [`VpsAvailabilityPromise.Cancel()`](/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/VpsAvailabilityPromise#cancel). Any registered callback will never be called.\n- [`Done`](/ar/reference/unity-arf/namespace/Google/XR/ARCoreExtensions#promisestate): The operation is complete. Use [`VpsAvailabilityPromise.Result`](/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/VpsAvailabilityPromise#result) to obtain the result.\n\nYou may continue checking [`VpsAvailabilityPromise.State`](/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/VpsAvailabilityPromise#state) until the task is complete.\n\nCancel the `InterruptiblePromise`\n---------------------------------\n\nUse [`VpsAvailabilityPromise.Cancel()`](/ar/reference/unity-arf/class/Google/XR/ARCoreExtensions/VpsAvailabilityPromise#cancel) to attempt to cancel the `InterruptiblePromise`. Due to thread parallelism, it may be possible that your cancel attempt does not actually succeed.\n\n\nUse the Geospatial API without VPS coverage\n-------------------------------------------\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."]]