RxJava एक प्रतिक्रिया करने वाली प्रोग्रामिंग लाइब्रेरी है. इसकी मदद से निगरानी किए जा सकने वाले क्रम का इस्तेमाल करके, एसिंक्रोनस और इवेंट-आधारित प्रोग्राम बनाए जाते हैं.
Maps Rx लाइब्रेरी की मदद से Android के लिए Maps SDK टूल और Android के लिए Places SDK टूल पर, एसिंक्रोनस इवेंट के देखे जा सकने वाले क्रम पाए जा सकते हैं, ताकि आप RxJava की सुविधाओं के बेहतर सेट का फ़ायदा पा सकें.
इंस्टॉल करना
अपने Google Maps प्रोजेक्ट में Maps Rx लाइब्रेरी इंस्टॉल करने के लिए:
अपनी मॉड्यूल-लेवल की
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.4.0' implementation 'io.reactivex.rxjava3:rxjava:3.1.8'
- इन बदलावों को सिंक करने के लिए, Android Studio में अपना प्रोजेक्ट फिर से बनाएं.
इस्तेमाल का उदाहरण
GoogleMap ऑब्जेक्ट पर एक एक्सटेंशन फ़ंक्शन के रूप में मार्कर क्लिक इवेंट के लिए एक ऑब्ज़र्वेबल पाएं:
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 }
आगे क्या करना है
- Maps Rx लाइब्रेरी GitHub प्रोजेक्ट पेज देखें.
- Maps Rx Library API का रेफ़रंस देखें.