ספריית RxJava

RxJava היא ספריית תכנות תגובתית לחיבור תוכניות אסינכרוניות ומבוססות אירועים באמצעות רצפים גלויים.

ספריית Places Rx מאפשרת לקבל רצפים גלויים לאירועים אסינכרוניים ב-SDK של מפות Google ל-Android וב-Place SDK ל-Android, כדי שתוכלו ליהנות מהמגוון העשיר של תכונות RxJava.

התקנה

כדי להתקין את ספריית מקומות Rx בפרויקט מפות Google:

  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 Studio כדי לסנכרן את השינויים האלה.

שימוש לדוגמה

בדוגמה הבאה אפשר לראות איך מקבלים סינגל ונרשמים למינוי כשמביאים פרטי מקום:

  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}")
    }
  )
}

המאמרים הבאים