RxJava เป็นไลบรารีการเขียนโปรแกรมเชิงรับสำหรับการเขียนโปรแกรมที่ไม่พร้อมกันและอิงตามเหตุการณ์โดยใช้ลำดับที่สังเกตได้
ไลบรารี Places Rx ช่วยให้คุณได้รับลำดับเหตุการณ์ที่ไม่พร้อมกันที่สังเกตได้บน Maps SDK สำหรับ Android และ Places SDK สำหรับ Android เพื่อให้คุณใช้ประโยชน์จากชุดฟีเจอร์ของ RxJava ที่มีมากมายได้
การติดตั้ง
วิธีติดตั้งห้องสมุด Places Rx ในโครงการ Google แผนที่ของคุณ
เพิ่มทรัพยากร Dependency ต่อไปนี้ในไฟล์
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'
- สร้างโปรเจ็กต์อีกครั้งใน 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}") } ) }
ขั้นตอนถัดไป
- ดูหน้าไลบรารี Places Rx ของโปรเจ็กต์ GitHub
- ดูเอกสารอ้างอิง API ไลบรารีของ Places Rx