为以 Android 为目标平台的 Unity (AR Foundation) 应用启用 Geospatial API
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
配置应用的设置,以便其可以使用 Geospatial API。
前提条件
在继续操作之前,请确保您了解基本 AR 概念以及如何配置 ARCore 会话。
如需详细了解 Geospatial API,请参阅 Geospatial API 简介。
如果您刚开始使用 ARCore 进行开发,请参阅使用入门,了解软件和硬件要求、前提条件以及特定于您所用平台的其他信息。
如需使用 ARCore Geospatial API,您的项目必须支持 AR Foundation 和 AR Foundation 的 ARCore 扩展。
启用 ARCore API
在应用中使用 Visual Positioning System (VPS) 之前,您必须先在新建或现有的 Google Cloud 项目中启用 ARCore API。此服务负责托管、存储和解析地理空间锚点。
首选无密钥授权,但也支持 API 密钥授权。
将所需的库添加到您的应用
授权应用调用 ARCore API 后,您必须添加库才能在应用中启用地理空间功能。
- 依次选择 Edit > Project Settings > XR Plug-In Management > ARCore Extensions。
- 在可选功能下,选择 Geospatial。

在会话配置中启用地理空间功能
在应用中启用地理空间功能后,请在应用的 AR 会话配置中启用地理空间功能,以便应用能够与 ARCore API 通信:
- 确保项目的 Assets 文件夹包含 ARCoreExtensionsConfig 可编写脚本的对象。如需创建此类资源,请在 Assets 窗格中右键点击,然后依次选择 Create > XR > ARCore Extensions Config。
在 Assets 文件夹中选择 ARCoreExtensionsConfig 可脚本化对象,然后将地理空间模式设置为已启用。

配置 ARCore Extensions 游戏对象以使用 ARCoreExtensionsConfig 配置。在 Hierarchy 窗格中,找到您在首次设置 ARCore Extensions 时创建的 ARCore Extensions 游戏对象,然后将 ARCore Extensions Config 字段连接到 Assets 文件夹中的 ARCoreExtensionsConfig 可编程对象。

提示用户允许使用设备数据
使用 ARCore Geospatial API 的应用必须向用户显示提示,以便用户确认并允许使用其设备中的数据。如需了解详情,请参阅用户隐私权要求。
检查设备兼容性
并非所有支持 ARCore 的设备都支持 Geospatial API。如需检查用户设备的兼容性,请调用 AREarthManager.IsGeospatialModeSupported()
。如果此方法返回 FeatureSupported.Unsupported
,请勿尝试配置会话。
在运行时向用户请求位置信息权限
在 ARCoreExtensions.Update()
中启用地理空间模式时,ARCore 扩展程序会自动请求适当的位置信息权限。如果用户未授予确切位置信息权限,会话将无法恢复,并会生成“未授予权限”错误。这是终止错误,需要重新启动才能再次触发权限请求。
检查设备当前位置的地理空间可用性
由于 Geospatial API 会结合使用 VPS 和 GPS 来确定地理空间姿势,因此只要设备能够确定其位置,就可以使用该 API。在 GPS 精度较低的区域(例如室内空间和密集的城市环境)中,该 API 将依赖于 VPS 覆盖范围来生成高精度姿势。在典型条件下,VPS 预计可提供约 5 米的位置精度和 5 度旋转精度。使用 AREarthManager.CheckVpsAvailability()
确定给定位置是否有 VPS 覆盖。
Geospatial API 还可在未覆盖 VPS 的区域使用。在头顶上方没有或几乎没有遮挡物的室外环境中,GPS 可能就足以生成高精度的姿势。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-14。
[null,null,["最后更新时间 (UTC):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."]]