取得裝置相機's 地理空間姿勢
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
設定應用程式使用 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%。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間: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."]]