مكتبة RxJava

RxJava هي مكتبة برمجة تفاعلية لإنشاء برامج غير متزامنة قائمة على الأحداث باستخدام تسلسلات يمكن ملاحظتها.

تتيح لك مكتبة الأماكن Rx إمكانية تلقّي تسلسلات يمكن ملاحظتها للأحداث غير المتزامنة على حزمة تطوير البرامج لتطبيق "خرائط Google" لنظام التشغيل Android وحزمة تطوير البرامج لتطبيق "الأماكن" على نظام التشغيل 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" لمزامنة هذه التغييرات.

مثال على الاستخدام

يوضح المثال التالي كيفية تلقي فردي والاشتراك فيه عند جلب تفاصيل المكان:

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

الخطوات التالية