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

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

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

AR 세션이 시작되기 전에 주어진 가로 위치에서 VPS 사용 가능 여부를 확인하고 이를 사용하여 보다 구체적인 환경을 만들 수 있습니다(예: VPS를 사용할 수 있을 때만 'AR 시작' 버튼을 표시).

ARCore API 사용 설정

앱에서 ARCore API를 사용 설정하여 VPS 가용성을 확인해야 합니다.

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

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

Geospatial API는 기기가 위치를 파악할 수 있는 모든 곳에서 사용할 수 있습니다. AR 환경이 VPS 적용 범위에 달려 있는 경우 Session.checkVpsAvailabilityAsync()를 사용하여 주어진 가로 위치에서 VPS 사용 가능 여부를 확인하는 비동기 작업인 VpsAvailabilityFuture를 얻을 수 있습니다. VpsAvailabilityFuture가 있으면 폴링 또는 콜백을 통해 결과를 가져올 수 있습니다.

결과 폴링

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

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

Java

// 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 상태가 된 직후 기본 스레드에서 호출됩니다.

Java

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만으로도 높은 정확도로 포즈를 취할 수 있습니다.

다음 단계