Lấy tư thế Không gian địa lý của máy ảnh
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Sau khi định cấu hình chế độ cài đặt của ứng dụng để sử dụng API không gian địa lý, bạn có thể gọi Earth.getCameraGeospatialPose()
để lấy GeospatialPose
mô tả vị trí không gian địa lý của thiết bị cho máy ảnh trong khung hình mới nhất. Tư thế này, được quản lý trong đối tượng Earth
, chứa các thông tin sau:
- Vị trí, được biểu thị bằng vĩ độ và kinh độ
- Cao độ
- Hướng gần đúng với hướng người dùng đang đối mặt trong hệ toạ độ EUS, trong đó X+ chỉ về hướng đông, Y+ chỉ lên trên và Z+ chỉ về hướng nam
Kiểm tra trạng thái theo dõi
Giá trị không gian địa lý chỉ hợp lệ khi Earth.TrackingState
là TrackingState.TRACKING
. Hãy nhớ gói tất cả lệnh gọi API không gian địa lý trong một khối điều khiển 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.
}
Nếu Earth.TrackingState
không trở thành TrackingState.TRACKING
, thì Earth.TrackingState
có thể là TrackingState.PAUSED
hoặc TrackingState.STOPPED
. Nếu không có điều kiện nào trong số này là đúng, hãy kiểm tra Earth.Earthstate
. Thành phần này cho thấy các trạng thái lỗi khác có thể khiến đối tượng Earth
không theo dõi được.
Điều chỉnh tư thế để đảm bảo tính chính xác
Khi thiết bị đứng thẳng theo hướng mặc định, các góc độ nghiêng (X+) và nghiêng (Z+) có xu hướng chính xác do được căn chỉnh tự nhiên với tính năng theo dõi AR. Tuy nhiên, các góc xoay ngang (Y+) có thể thay đổi tuỳ thuộc vào tình trạng sẵn có của dữ liệu VPS và điều kiện thời gian tại vị trí đó. Ứng dụng của bạn có thể phải điều chỉnh để đảm bảo độ chính xác.
GeospatialPose.getOrientationYawAccuracy()
cung cấp thông tin ước tính về độ chính xác cho các góc yaw (Y+) cho một GeospatialPose
nhất định. Độ chính xác của độ lệch hướng là một con số mô tả bán kính (tính bằng độ) của mức độ tin cậy thứ 68 theo tỷ lệ phần trăm xung quanh các góc lệch hướng được trả về từ GeospatialPose.getEastUpSouthQuaternion()
. Nói cách khác, có 68% khả năng góc xoay thực của GeospatialPose
là chính xác.
Giá trị càng lớn thì độ chính xác càng thấp. Ví dụ: nếu góc nghiêng ước tính là 60 độ và độ chính xác của góc nghiêng là 10 độ, thì có 68% khả năng góc nghiêng thực tế nằm trong khoảng từ 50 đến 70 độ.
Bước tiếp theo
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\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."]]