RxJava लाइब्रेरी

RxJava एक रिऐक्टिव प्रोग्रामिंग लाइब्रेरी है. इसकी मदद से, एसिंक्रोनस और इवेंट पर आधारित प्रोग्राम बनाए जाते हैं मॉनिटर किए जा सकने वाले क्रमों का इस्तेमाल किया जाता है.

Maps Rx लाइब्रेरी की मदद से, Android के लिए Maps SDK पर एसिंक्रोनस इवेंट के लिए मॉनिटर किए जा सकने वाले क्रम पाए जा सकते हैं और Android के लिए Places SDK टूल की जानकारी जोड़ी है. इससे आपको RxJava की बेहतरीन सुविधाओं का फ़ायदा मिल सकता है.

इंस्टॉल करना

अपने Google Maps प्रोजेक्ट में Maps 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:19.0.0")
        implementation("com.google.android.libraries.places:places:3.5.0")
        implementation("io.reactivex.rxjava3:rxjava:3.1.8")
    
  2. इन बदलावों को सिंक करने के लिए, Android Studio में अपना प्रोजेक्ट फिर से बनाएं.

इस्तेमाल का उदाहरण

Google Maps ऑब्जेक्ट पर एक्सटेंशन फ़ंक्शन के तौर पर, मार्कर क्लिक इवेंट के लिए मॉनिटर किया जा सकने वाला कोई नतीजा पाएं:

googleMap.markerClickEvents()
  .subscribe { marker ->
    Log.d("MapsRx", "Marker ${marker.title} was clicked")
  }

अगले उदाहरण में बताया गया है कि एक-दूसरे से जोड़ने के लिए, RxJava ऑपरेटर merge का इस्तेमाल कैसे किया जा सकता है एक ही ऑब्ज़र्वेबल स्ट्रीम में अलग-अलग कैमरा इवेंट:

Observable.merge(
  googleMap.cameraIdleEvents(),
  googleMap.cameraMoveEvents(),
  googleMap.cameraMoveCanceledEvents(),
  googleMap.cameraMoveStartedEvents()
).subscribe {
  // Notified when any camera event occurs
}

आगे क्या करना है