获取设备相机的地理空间姿势
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
将应用的设置配置为使用 Geospatial API 后,您可以调用 Earth.getCameraGeospatialPose()
来获取 GeospatialPose
,该值描述了设备在最新帧中相机的地理空间定位。此姿势在 Earth
对象中进行管理,包含以下信息:
- 位置(以纬度和经度表示)
- 海拔高度
- 大致相当于用户在 EUS 坐标系中朝向的方向,其中 X+ 指向东方,Y+ 指向上方,Z+ 指向南方
检查跟踪状态
地理空间值仅在 Earth.TrackingState
为 TrackingState.TRACKING
时有效。请务必将所有 Geospatial API 调用封装在 Earth.TrackingState
控制块中。
Java
if (earth != null && earth.getTrackingState() == TrackingState.TRACKING) {
GeospatialPose cameraGeospatialPose = earth.getCameraGeospatialPose();
// cameraGeospatialPose contains geodetic location, rotation, and confidences values.
}
Kotlin
if (earth.trackingState == TrackingState.TRACKING) {
val cameraGeospatialPose = earth.cameraGeospatialPose
// cameraGeospatialPose contains geodetic location, rotation, and confidences values.
}
如果 Earth.TrackingState
未变为 TrackingState.TRACKING
,则 Earth.TrackingState
可能是 TrackingState.PAUSED
或 TrackingState.STOPPED
。如果这两种情况都不满足,请检查 Earth.Earthstate
,其中会显示可能导致 Earth
对象无法跟踪的其他错误状态。
调整姿势以提高准确性
当设备处于默认屏幕方向的竖屏状态时,由于与 AR 跟踪自然对齐,俯仰角 (X+) 和滚动角 (Z+) 通常是精确的。不过,偏航角 (Y+) 可能会因 VPS 数据可用性和相应位置的时间条件而异。您的应用可能需要进行调整以提高准确性。
GeospatialPose.getOrientationYawAccuracy()
会为特定 GeospatialPose
的偏航角 (Y+) 提供精度估算值。方向偏摆精度是一个数字,用于描述 GeospatialPose.getEastUpSouthQuaternion()
返回的偏摆角度周围第 68 个百分位数置信度的半径(以度为单位)。换句话说,GeospatialPose
的真实偏航角有 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\u003eThe Geospatial API provides the device's location, altitude, and orientation using the \u003ccode\u003eEarth\u003c/code\u003e object and \u003ccode\u003eGeospatialPose\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eGeospatial data is only valid when \u003ccode\u003eEarth.TrackingState\u003c/code\u003e is \u003ccode\u003eTrackingState.TRACKING\u003c/code\u003e; ensure your code handles other tracking states.\u003c/p\u003e\n"],["\u003cp\u003eWhile pitch and roll are generally precise, yaw accuracy can vary and may require adjustments in your application.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eGeospatialPose.getOrientationYawAccuracy()\u003c/code\u003e provides an estimate of yaw accuracy, with larger values indicating lower accuracy.\u003c/p\u003e\n"],["\u003cp\u003eYou can leverage the Geospatial pose to place Geospatial anchors in your AR experience.\u003c/p\u003e\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 [`Earth.getCameraGeospatialPose()`](/ar/reference/java/com/google/ar/core/Earth#getCameraGeospatialPose-) to obtain a [`GeospatialPose`](/ar/reference/java/com/google/ar/core/GeospatialPose) that describes the device's Geospatial positioning for the camera in the latest frame. This pose, managed in an [`Earth`](/ar/reference/java/com/google/ar/core/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 [`Earth.TrackingState`](/ar/reference/java/com/google/ar/core/TrackingState) is [`TrackingState.TRACKING`](/ar/reference/java/com/google/ar/core/TrackingState#tracking). Make sure to wrap all Geospatial API calls in a [`Earth.TrackingState`](/ar/reference/java/com/google/ar/core/TrackingState) control block. \n\n### Java\n\n```java\nif (earth != null && earth.getTrackingState() == TrackingState.TRACKING) {\n GeospatialPose cameraGeospatialPose = earth.getCameraGeospatialPose();\n // cameraGeospatialPose contains geodetic location, rotation, and confidences values.\n}\n```\n\n### Kotlin\n\n```kotlin\nif (earth.trackingState == TrackingState.TRACKING) {\n val cameraGeospatialPose = earth.cameraGeospatialPose\n // cameraGeospatialPose contains geodetic location, rotation, and confidences values.\n}\n```\n\nIf [`Earth.TrackingState`](/ar/reference/java/com/google/ar/core/TrackingState) does not become [`TrackingState.TRACKING`](/ar/reference/java/com/google/ar/core/TrackingState#tracking), [`Earth.TrackingState`](/ar/reference/java/com/google/ar/core/TrackingState) may be [`TrackingState.PAUSED`](/ar/reference/java/com/google/ar/core/TrackingState#paused) or [`TrackingState.STOPPED`](/ar/reference/java/com/google/ar/core/TrackingState#stopped). If neither of these conditions are true, check [`Earth.Earthstate`](/ar/reference/java/com/google/ar/core/Earth.EarthState), which shows other error states that may keep the [`Earth`](/ar/reference/java/com/google/ar/core/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[`GeospatialPose.getOrientationYawAccuracy()`](/ar/reference/java/com/google/ar/core/GeospatialPose#getOrientationYawAccuracy-) provides an accuracy estimate for the yaw (Y+) angles for a certain [`GeospatialPose`](/ar/reference/java/com/google/ar/core/GeospatialPose). 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 [`GeospatialPose.getEastUpSouthQuaternion()`](/ar/reference/java/com/google/ar/core/GeospatialPose#getEastUpSouthQuaternion-). In other words, there is a 68% chance that the [`GeospatialPose`](/ar/reference/java/com/google/ar/core/GeospatialPose)'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/java/geospatial/anchors#wgs84_anchors) by obtaining the anchor's Geospatial pose."]]