获取设备相机的地理空间姿势
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
将应用的设置配置为使用 Geospatial API 后,您可以调用 ArEarth_getCameraGeospatialPose
来获取 ArGeospatialPose
,该值描述了设备在最新帧中相机的地理空间定位。此姿势在 ArEarth
对象中进行管理,包含以下信息:
- 位置(以纬度和经度表示)
- 海拔高度
- 大致相当于用户在 EUS 坐标系中朝向的方向,其中 X+ 指向东方,Y+ 指向上方,Z+ 指向南方
检查跟踪状态
地理空间值仅在 ArEarth.ArTrackingState
为 ArTrackingState.AR_TRACKING_STATE_TRACKING
且 ArEarth.ArEarthState
为 AR_EARTH_STATE_ENABLED
时有效。请务必将所有 Geospatial API 调用封装在 ArEarth.ArTrackingState
控制块中。
if (ar_earth != NULL) {
ArTrackingState earth_tracking_state = AR_TRACKING_STATE_STOPPED;
ArTrackable_getTrackingState(ar_session, (ArTrackable*)ar_earth,
&earth_tracking_state);
if (earth_tracking_state == AR_TRACKING_STATE_TRACKING) {
ArGeospatialPose* camera_geospatial_pose = NULL;
ArGeospatialPose_create(ar_session, &camera_geospatial_pose);
ArEarth_getCameraGeospatialPose(ar_session, ar_earth,
camera_geospatial_pose);
// camera_geospatial_pose contains geodetic location, rotation, and
// confidences values.
ArGeospatialPose_destroy(camera_geospatial_pose);
}
}
如果 ArEarth.ArTrackingState
未变为 ArTrackingState.AR_TRACKING_STATE_TRACKING
,则 ArEarth.ArTrackingState
可能是 AR_TRACKING_STATE_PAUSED
或 AR_TRACKING_STATE_STOPPED
。如果这两种情况都不满足,请检查 ArEarth.ArEarthState
,其中会显示可能导致 ArEarth
对象无法跟踪的其他错误状态。
调整姿势以提高准确性
当设备处于默认屏幕方向的竖屏状态时,由于与 AR 跟踪自然对齐,俯仰角 (X+) 和滚动角 (Z+) 通常是精确的。不过,偏航角 (Y+) 可能会因 VPS 数据可用性和相应位置的时间条件而异。您的应用可能需要进行调整以提高准确性。
ArGeospatialPose_getOrientationYawAccuracy()
会为特定 ArGeospatialPose
的偏航角 (Y+) 提供精度估算值。方向偏摆精度是一个数字,用于描述 ArGeospatialPose_getEastUpSouthQuaternion()
返回的偏摆角度周围第 68 个百分位数置信度的半径(以度为单位)。换句话说,ArGeospatialPose
的真实偏航角有 68% 的概率是准确的。
值越大,准确性越低。例如,如果估算的偏摆角度为 60 度,且偏摆准确度为 10 度,则真实偏摆角度介于 50 度和 70 度之间的概率为 68%。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eAfter configuring your app, call \u003ccode\u003eArEarth_getCameraGeospatialPose\u003c/code\u003e to obtain the device's geospatial positioning, including location (latitude, longitude), altitude, and orientation, through an \u003ccode\u003eArGeospatialPose\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eGeospatial values are only valid when \u003ccode\u003eArEarth.ArTrackingState\u003c/code\u003e is \u003ccode\u003eAR_TRACKING_STATE_TRACKING\u003c/code\u003e and \u003ccode\u003eArEarth.ArEarthState\u003c/code\u003e is \u003ccode\u003eAR_EARTH_STATE_ENABLED\u003c/code\u003e, requiring you to wrap API calls in a tracking state control block.\u003c/p\u003e\n"],["\u003cp\u003eWhile pitch and roll angles tend to be accurate, yaw angles may vary and require adjustments using the \u003ccode\u003eArGeospatialPose_getOrientationYawAccuracy\u003c/code\u003e function to assess accuracy and confidence levels.\u003c/p\u003e\n"]]],["After configuring app settings, call `ArEarth_getCameraGeospatialPose` to get the device's geospatial position (`ArGeospatialPose`). This pose contains latitude, longitude, altitude, and orientation. Geospatial data is valid only when `ArTrackingState` is `AR_TRACKING_STATE_TRACKING` and `ArEarthState` is `AR_EARTH_STATE_ENABLED`. Ensure API calls are within a `ArTrackingState` control block. The yaw angle's accuracy can vary; `ArGeospatialPose_getOrientationYawAccuracy` estimates its precision. Larger values of accuracy indicate lower precision of the Yaw angle.\n"],null,["# Obtain the device camera's Geospatial pose\n\nOnce you have configured your app's settings to use the Geospatial API, you can call [`ArEarth_getCameraGeospatialPose`](/ar/reference/c/group/ar-earth#arearth_getcamerageospatialpose) to obtain a [`ArGeospatialPose`](/ar/reference/c/group/ar-geospatial-pose) that describes the device's Geospatial positioning for the camera in the latest frame. This pose, managed in an [`ArEarth`](/ar/reference/c/group/ar-earth) object, contains the following information:\n\n- Location, expressed in latitude and longitude\n- Altitude\n- An orientation approximating the direction the user is facing in the EUS coordinate system with X+ pointing east, Y+ pointing up, and Z+ pointing south\n\nCheck the tracking state\n------------------------\n\nGeospatial values are only valid while [`ArEarth.ArTrackingState`](/ar/reference/c/group/shared-types#artrackingstate) is [`ArTrackingState.AR_TRACKING_STATE_TRACKING`](/ar/reference/c/group/shared-types#artrackingstate) and [`ArEarth.ArEarthState`](/ar/reference/c/group/ar-earth#arearthstate) is [`AR_EARTH_STATE_ENABLED`](/ar/reference/c/group/ar-earth#arearthstate). Make sure to wrap all Geospatial API calls in a [`ArEarth.ArTrackingState`](/ar/reference/c/group/shared-types#artrackingstate) control block. \n\n```c\nif (ar_earth != NULL) {\n ArTrackingState earth_tracking_state = AR_TRACKING_STATE_STOPPED;\n ArTrackable_getTrackingState(ar_session, (ArTrackable*)ar_earth,\n &earth_tracking_state);\n if (earth_tracking_state == AR_TRACKING_STATE_TRACKING) {\n ArGeospatialPose* camera_geospatial_pose = NULL;\n ArGeospatialPose_create(ar_session, &camera_geospatial_pose);\n ArEarth_getCameraGeospatialPose(ar_session, ar_earth,\n camera_geospatial_pose);\n // camera_geospatial_pose contains geodetic location, rotation, and\n // confidences values.\n ArGeospatialPose_destroy(camera_geospatial_pose);\n }\n}\n```\n\nIf [`ArEarth.ArTrackingState`](/ar/reference/c/group/shared-types#artrackingstate) does not become [`ArTrackingState.AR_TRACKING_STATE_TRACKING`](/ar/reference/c/group/shared-types#artrackingstate), [`ArEarth.ArTrackingState`](/ar/reference/c/group/shared-types#artrackingstate) may be [`AR_TRACKING_STATE_PAUSED`](/ar/reference/c/group/shared-types#artrackingstate) or [`AR_TRACKING_STATE_STOPPED`](/ar/reference/c/group/shared-types#artrackingstate). If neither of these conditions are true, check [`ArEarth.ArEarthState`](/ar/reference/c/group/ar-earth#arearthstate), which shows other error states that may keep the [`ArEarth`](/ar/reference/c/group/ar-earth) object from tracking.\n\nAdjust the pose for accuracy\n----------------------------\n\nWhen the device is upright in the default orientation, the pitch (X+) and roll (Z+) angles tend to be precise due to a natural alignment with AR tracking. However, the yaw (Y+) angles can vary depending on VPS data availability and temporal conditions at the location. Your app may have to make adjustments for accuracy.\n\n[`ArGeospatialPose_getOrientationYawAccuracy()`](/ar/reference/c/group/ar-earth#argeospatialpose_getorientationyawaccuracy) provides an accuracy estimate for the yaw (Y+) angles for a certain [`ArGeospatialPose`](/ar/reference/c/group/ar-geospatial-pose). The orientation yaw accuracy is a number that describes the radius, in degrees, of the 68th percentile confidence level around the yaw angles returned from [`ArGeospatialPose_getEastUpSouthQuaternion()`](/ar/reference/c/group/ar-geospatial-pose#argeospatialpose_geteastupsouthquaternion). In other words, there is a 68% chance that the [`ArGeospatialPose`](/ar/reference/c/group/ar-geospatial-pose)'s true yaw angle is accurate.\n\nLarger values indicate lower accuracy. For example, if the estimated yaw angle is 60 degrees and the yaw accuracy is 10 degrees, then there is a 68% probability that the true yaw angle is between 50 and 70 degrees.\n\nWhat's next\n-----------\n\n- Place a [Geospatial anchor](/ar/develop/c/geospatial/anchors#wgs84_anchors) by obtaining the anchor's Geospatial pose."]]