기기의 현재 위치에서 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 범위에 따라 달라지는 경우 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만 사용해도 높은 정확도로 자세를 취할 수 있습니다.

다음 단계