RxJava 라이브러리

RxJava는 관측 가능한 시퀀스를 사용하여 비동기 프로그램 및 이벤트 기반 프로그램을 작성하기 위한 반응형 프로그래밍 라이브러리입니다.

장소 Rx 라이브러리를 사용하면 Android용 Maps SDK 및 Android용 Places SDK에서 비동기 이벤트에 대한 관측 가능한 시퀀스를 수신하여 다양한 RxJava 기능을 활용할 수 있습니다.

설치

Google 지도 프로젝트에 Places Rx 라이브러리를 설치하려면 다음 단계를 따르세요.

  1. 모듈 수준 build.gradle 파일에 다음 종속 항목을 추가합니다.

    dependencies {
        // RxJava bindings for the Maps SDK
        implementation 'com.google.maps.android:maps-rx:1.0.0'
    
        // RxJava bindings for the Places SDK
        implementation 'com.google.maps.android:places-rx:1.0.0'
    
        // It is recommended to also include the latest Maps SDK, Places SDK and RxJava so you
        // have the latest features and bug fixes.
        implementation "com.google.android.gms:play-services-maps:18.2.0"
        implementation 'com.google.android.libraries.places:places:3.3.0'
        implementation 'io.reactivex.rxjava3:rxjava:3.1.8'
    
  2. Android 스튜디오에서 프로젝트를 재구성하여 변경사항을 동기화하세요.

사용 예

다음 예는 장소 세부정보를 가져올 때 Single을 수신하고 구독할 수 있는 방법을 보여줍니다.

  placesClient.fetchPlace(
    placeId = "thePlaceId",
    placeFields = listOf(Place.Field.ID, Place.Field.NAME, Place.Field.ADDRESS),
    actions = {}
  ).subscribe(
    { response ->
      Log.d("PlacesRx", "Successfully got place ${response.place.id}")
    },
    { error ->
      Log.e("PlacesRx", "Could not get place: ${error.message}")
    }
  )
}

다음 단계