RxJava เป็นไลบรารีการเขียนโปรแกรมแบบรีแอกทีฟสำหรับการเขียนโปรแกรมแบบอะซิงโครนัสและ แบบอิงตามเหตุการณ์โดยใช้ลำดับที่สังเกตได้
ไลบรารี Places Rx ช่วยให้คุณรับลำดับที่สังเกตได้สำหรับเหตุการณ์แบบอะซิงโครนัสใน Maps SDK สำหรับ Android และ Places SDK สำหรับ Android เพื่อให้คุณ ใช้ประโยชน์จากฟีเจอร์ RxJava ที่หลากหลายได้
การติดตั้ง
วิธีติดตั้งไลบรารี Places Rx ในโปรเจ็กต์ Google Maps
เพิ่มทรัพยากร Dependency ต่อไปนี้ลงในไฟล์
build.gradleระดับโมดูลdependencies { // RxJava bindings for the Maps SDK implementation(libs.maps.rx) // RxJava bindings for the Places SDK implementation(libs.places.rx) // 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:20.0.0") implementation("com.google.android.libraries.places:places:5.3.0") implementation("io.reactivex.rxjava3:rxjava:3.1.12")
สร้างโปรเจ็กต์ใหม่ใน Android Studio เพื่อซิงค์การเปลี่ยนแปลงเหล่านี้
ตัวอย่างการใช้
รับ Single และ ติดตามเมื่อดึงข้อมูลรายละเอียดสถานที่
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}") } ) }
ขั้นตอนถัดไป
- ดูหน้าโปรเจ็กต์ GitHub ของไลบรารี Places Rx
- ดูเอกสารอ้างอิง API ของไลบรารี Places Rx