检查设备当前所在位置的 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
Geospatial API 还可在未覆盖 VPS 的区域使用。在头顶上方没有或几乎没有遮挡物的室外环境中,GPS 可能就足以生成高精度的姿势。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-14。
[null,null,["最后更新时间 (UTC):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."]]