기기의 현재 위치에서 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 적용 범위에 달려 있는 경우 ArSession_checkVpsAvailabilityAsync()를 사용하여 주어진 가로 위치에서 VPS 사용 가능 여부를 확인하는 비동기 작업인 ArVpsAvailabilityFuture를 얻을 수 있습니다. ArVpsAvailabilityFuture가 있으면 폴링 또는 콜백을 통해 결과를 가져올 수 있습니다.

결과 폴링

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

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

// Obtain a ArVpsAvailabilityFuture and store it somewhere.
ArVpsAvailabilityFuture* future = NULL;
CHECK(ArSession_checkVpsAvailabilityAsync(ar_session, latitude, longitude,
                                          NULL, NULL, &future) == AR_SUCCESS);

// Poll ArVpsAvailabilityFuture later, for example, in a render loop.
ArFutureState future_state = AR_FUTURE_STATE_PENDING;
ArFuture_getState(ar_session, (ArFuture*)future, &future_state);
if (future_state == AR_FUTURE_STATE_DONE) {
  ArVpsAvailability vps_availability = AR_VPS_AVAILABILITY_UNKNOWN;
  ArVpsAvailabilityFuture_getResult(ar_session, future, &vps_availability);
  switch (vps_availability) {
    case AR_VPS_AVAILABILITY_AVAILABLE:
      // VPS is available at this location.
      break;
    case AR_VPS_AVAILABILITY_UNAVAILABLE:
      // VPS is unavailable at this location.
      break;
    case AR_VPS_AVAILABILITY_ERROR_NETWORK_CONNECTION:
      // The external service could not be reached due to a network connection
      // error.
      break;

      // Handle other error states, e.g.
      // AR_VPS_AVAILABILITY_ERROR_RESOURCE_EXHAUSTED,
      // AR_VPS_AVAILABILITY_ERROR_INTERNAL, ...
  }
  ArFuture_release((ArFuture*)future);
}

콜백을 통해 결과 가져오기

콜백을 통해 ArFuture의 결과를 가져올 수도 있습니다. ArSession_checkVpsAvailabilityAsync()를 사용하고 callback를 제공합니다. 이 callbackArFutureAR_FUTURE_STATE_DONE 상태가 된 직후 기본 스레드에서 호출됩니다.

void vps_availability_callback(void* context, ArVpsAvailability availability) {
  // Callback is called on the Main thread.

  // Handle the ArVpsAvailability result as shown above.
  // For example, show UI that enables your AR view.

  // It is a best practice to free `context` memory at the end of the callback.
  free(context);
}

void check_availability_with_callback(ArSession* ar_session, double latitude,
                                      double longitude) {
  ArVpsAvailabilityFuture* future = NULL;
  void* context = NULL;
  CHECK(ArSession_checkVpsAvailabilityAsync(
      ar_session, latitude, longitude, context, vps_availability_callback,
      &future) == AR_SUCCESS);
}

ArFuture 취소

ArFuture_cancel()를 사용하여 ArFuture를 취소해 봅니다. 스레드 병렬 처리로 인해 취소 시도가 실제로 성공하지 못할 수도 있습니다. ArFuture_cancel()는 이 시도가 성공하면 1, 그러지 않으면 0를 반환합니다.

VPS 적용 범위 없이 Geospatial API 사용

Geospatial API는 VPS 커버리지가 없는 영역에서도 사용할 수 있습니다. 오버헤드가 거의 없거나 전혀 없는 야외 환경에서는 GPS만으로도 높은 정확도로 포즈를 취할 수 있습니다.

다음 단계