기기의 현재 위치에서 VPS 사용 가능 여부 확인

Geospatial API는 VPS 및 GPS 데이터의 조합을 사용하여 정확도가 높은 지리정보 포즈를 생성합니다. API는 기기가 위치를 확인할 수 있는 모든 위치에서 사용할 수 있습니다.

  • 실내 공간 및 밀집한 도시 환경과 같이 GPS 정확도가 낮은 지역에서는 API가 VPS 범위를 사용하여 매우 정확한 포즈를 생성합니다.
  • 오버헤드 장애물이 거의 또는 전혀 없는 실외 환경에서 Geospatial API는 사용 가능한 GPS 위치 데이터를 사용하여 높은 정확도로 지리정보 포즈를 생성할 수 있습니다.

AR 세션이 시작되기 전에 지정된 가로 위치에서 VPS 사용 가능 여부를 확인하고 이를 사용하여 더 구체적인 환경을 만들 수 있습니다(예: 'AR 시작' 표시). 버튼을 클릭합니다.

ARCore API 사용 설정

VPS 사용 가능 여부를 확인하려면 앱에서 ARCore API를 사용 설정해야 합니다.

ARCore API가 사용 설정되면 다음 작업 없이 VPS 가용성을 확인할 수 있습니다.

앱에서 VPS 사용 가능 여부 확인

Geospatial API는 기기가 위치를 확인할 수 있는 모든 위치에서 사용할 수 있습니다. AR 환경이 VPS 범위에 따라 달라지는 경우 Session.checkVpsAvailabilityAsync()를 사용하여 지정된 가로 위치에서 VPS 사용 가능 여부를 확인하는 비동기 작업인 VpsAvailabilityFuture를 가져올 수 있습니다. VpsAvailabilityFuture를 가져온 후에는 폴링 또는 콜백을 통해 결과를 가져올 수 있습니다.

결과 설문조사

Future.getState()를 사용하여 Future의 상태를 가져옵니다. 다음과 같은 세 가지 상태가 있습니다.

작업이 완료될 때까지 Future.getState()를 계속 확인할 수 있습니다.

자바

// Obtain a VpsAvailabilityFuture and store it somewhere.
VpsAvailabilityFuture future = session.checkVpsAvailabilityAsync(latitude, longitude, null);

// Poll VpsAvailabilityFuture later, for example, in a render loop.
if (future.getState() == FutureState.DONE) {
  switch (future.getResult()) {
    case AVAILABLE:
      // VPS is available at this location.
      break;
    case UNAVAILABLE:
      // VPS is unavailable at this location.
      break;
    case ERROR_NETWORK_CONNECTION:
      // The external service could not be reached due to a network connection error.
      break;

      // Handle other error states, e.g. ERROR_RESOURCE_EXHAUSTED, ERROR_INTERNAL, ...
  }
}

Kotlin

// Obtain a VpsAvailabilityFuture and store it somewhere.
val future = session.checkVpsAvailabilityAsync(latitude, longitude, null)

// Poll VpsAvailabilityFuture later, for example, in a render loop.
if (future.state == FutureState.DONE) {
  when (future.result) {
    VpsAvailability.AVAILABLE -> {
      // VPS is available at this location.
    }
    VpsAvailability.UNAVAILABLE -> {
      // VPS is unavailable at this location.
    }
    VpsAvailability.ERROR_NETWORK_CONNECTION -> {
      // The external service could not be reached due to a network connection error.
    }
    else -> {
      TODO("Handle other error states, e.g. ERROR_RESOURCE_EXHAUSTED, ERROR_INTERNAL, ...")
    }
  }
}

콜백을 통해 결과 가져오기

콜백을 통해 Future의 결과를 가져올 수도 있습니다. Session.checkVpsAvailabilityAsync()를 사용하고 callback을 제공합니다. 이 callbackFutureDONE 상태가 생기면 곧 기본 스레드에서 호출됩니다.

자바

session.checkVpsAvailabilityAsync(
    latitude,
    longitude,
    result -> {
      // Callback is called on the Main thread.
      switch (result) {
          // Handle the VpsAvailability result as shown above.
          // For example, show UI that enables your AR view.
      }
    });

Kotlin

session.checkVpsAvailabilityAsync(latitude, longitude) { result ->
  // Callback is called on the Main thread.

  // Handle the VpsAvailability result as shown above.
  // For example, show UI that enables your AR view.
  TODO("Handle VpsAvailability " + result)
}

Future 취소

Future.cancel()를 사용하여 Future 취소를 시도합니다. 스레드 동시 로드로 인해 취소 시도가 실제로 성공하지 못할 수도 있습니다. Future.cancel()는 이 시도에 성공하면 true를 반환하고 성공하지 못하면 false를 반환합니다.

VPS 범위 없이 Geospatial API 사용

Geospatial API는 VPS 범위가 없는 영역에서도 사용할 수 있습니다. 오버헤드 장애물이 거의 또는 전혀 없는 야외 환경에서는 GPS만 사용해도 높은 정확도로 자세를 취할 수 있습니다.

다음 단계