检查设备当前所在位置的 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 覆盖率,您可以使用 GARSession#checkVPSAvailabilityAtCoordinate:completionHandler:
获取 GARVPSAvailabilityFuture
,这是一个用于检查给定水平位置的 VPS 可用性的异步任务。
获取 GARVPSAvailabilityFuture
后,您可以通过轮询或回调来获取其结果。
轮询结果
使用 GARFuture.state
获取 Future
的状态。有三种不同的状态:
您可以继续查看 GARFuture.state
,直到任务完成。
通过回调获取结果
您还可以通过回调获取 Future
的结果。使用 GARSession#checkVPSAvailabilityAtCoordinate:completionHandler:
并提供 completionHandler
。在 Future
处于状态 GARFutureStateDone
后,系统会在主线程上立即调用此 completionHandler
。
取消 Future
使用 GARFuture#cancel
尝试取消 Future
。由于线程并行性,您的取消尝试可能实际上并未成功。
如果此尝试成功,GARFuture#cancel
会返回 YES
;否则,会返回 NO
。
在没有 VPS 覆盖的情况下使用 Geospatial API
Geospatial API 还可在未覆盖 VPS 的区域使用。在头顶上方没有或几乎没有遮挡物的室外环境中,GPS 可能就足以生成高精度的姿势。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eThe Geospatial API leverages VPS and GPS data to provide highly accurate location information, enabling AR experiences in various environments.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can confirm VPS availability at a specific location before initiating an AR session, allowing for tailored experiences like displaying an "Enter AR" button only when VPS is available.\u003c/p\u003e\n"],["\u003cp\u003eThe API offers flexibility by allowing the retrieval of VPS availability results through polling or a callback mechanism.\u003c/p\u003e\n"],["\u003cp\u003eEven in areas without VPS coverage, the Geospatial API can still function by relying on GPS data, particularly in outdoor settings with clear skies.\u003c/p\u003e\n"],["\u003cp\u003eAfter confirming VPS availability, developers can obtain the device's Geospatial pose to pinpoint the user's real-world location and build immersive AR experiences.\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 transforms. 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 transforms.\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 transforms 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/ios/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 [`GARSession#checkVPSAvailabilityAtCoordinate:completionHandler:`](/ar/reference/ios/interface/GARSession#checkvpsavailabilityatcoordinate:completionhandler:) to obtain a [`GARVPSAvailabilityFuture`](/ar/reference/ios/interface/GARVPSAvailabilityFuture), an asynchronous task that checks the VPS availability at a given horizontal position.\n\nOnce you have the [`GARVPSAvailabilityFuture`](/ar/reference/ios/interface/GARVPSAvailabilityFuture), you can obtain its result by polling or through a callback.\n\n\n### Poll the result\n\nUse [`GARFuture.state`](/ar/reference/ios/interface/GARFuture#state) to obtain the state of the `Future`. There are three different states:\n\n- `GARFutureStatePending`: The operation is not yet complete, so no result is known.\n- `GARFutureStateCancelled`: The operation has been cancelled by [`GARFuture#cancel`](/ar/reference/ios/interface/GARFuture#cancel). Any registered callback will never be called.\n- `GARFutureStateDone`: The operation is complete. Use [`GARVPSAvailabilityFuture.result`](/ar/reference/ios/interface/GARVPSAvailabilityFuture#result) to obtain the result.\n\nYou may continue checking [`GARFuture.state`](/ar/reference/ios/interface/GARFuture#state) until the task is complete.\n\n### Obtain the result through a callback\n\nYou can also obtain the result of a `Future` through a callback. Use [`GARSession#checkVPSAvailabilityAtCoordinate:completionHandler:`](/ar/reference/ios/interface/GARSession#checkvpsavailabilityatcoordinate:completionhandler:) and supply a `completionHandler`. This `completionHandler` will be called on the Main thread soon after the `Future` has state `GARFutureStateDone`.\n\nCancel the `Future`\n-------------------\n\nUse [`GARFuture#cancel`](/ar/reference/ios/interface/GARFuture#cancel) to attempt to cancel the `Future`. Due to thread parallelism, it may be possible that your cancel attempt does not actually succeed.\n\n`GARFuture#cancel` returns `YES` if this attempt was successful, and `NO` otherwise.\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/ios/geospatial/obtain-device-pose) to determine the exact location of the user's device in the real world."]]