Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
RxJava là một thư viện lập trình phản ứng để soạn các chương trình không đồng bộ và dựa trên sự kiện bằng cách
bằng cách sử dụng chuỗi quan sát được.
Thư viện Maps Rx
cho phép bạn nhận các trình tự có thể quan sát được cho các sự kiện không đồng bộ trên SDK Maps dành cho Android
và SDK Địa điểm dành cho Android để bạn có thể tận dụng bộ tính năng phong phú của RxJava.
Cài đặt
Cách cài đặt thư viện Maps Rx trong dự án Google Maps:
Thêm các phần phụ thuộc sau vào tệp build.gradle ở cấp mô-đun:
dependencies {// RxJava bindings for the Maps SDKimplementation("com.google.maps.android:maps-rx:1.0.0")// RxJava bindings for the Places SDKimplementation("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.2.0")implementation("com.google.android.libraries.places:places:4.3.1")implementation("io.reactivex.rxjava3:rxjava:3.1.8")
Hãy tạo lại dự án trong Android Studio để đồng bộ hoá những thay đổi này.
Ví dụ về cách sử dụng
Nhận một đối tượng Có thể quan sát cho các sự kiện nhấp chuột vào điểm đánh dấu dưới dạng một hàm tiện ích trên đối tượng GoogleMap:
googleMap.markerClickEvents().subscribe { marker ->
Log.d("MapsRx", "Marker ${marker.title} was clicked")}
Ví dụ tiếp theo cho bạn biết cách sử dụng toán tử RxJava, merge, để kết hợp
các sự kiện khác nhau trên camera vào một luồng Có thể quan sát:
Observable.merge(googleMap.cameraIdleEvents(),googleMap.cameraMoveEvents(),googleMap.cameraMoveCanceledEvents(),googleMap.cameraMoveStartedEvents()).subscribe {// Notified when any camera event occurs}
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-06-26 UTC."],[[["The Maps Rx library enables the use of RxJava with the Maps SDK and Places SDK for Android to handle asynchronous events."],["It provides observable sequences for events like marker clicks and camera movements, allowing developers to leverage RxJava features."],["You can install the library by adding specific dependencies to your `build.gradle` file and rebuilding your project."],["The library offers extension functions and operators to simplify the integration of RxJava with Google Maps functionality."]]],["The Maps Rx library, designed for use with RxJava, allows developers to receive observable sequences for asynchronous events on the Maps SDK and Places SDK for Android. To install, add dependencies for `maps-rx`, `places-rx`, and the latest `Maps SDK`, `Places SDK`, and `RxJava` to the `build.gradle` file, then rebuild the project. Developers can subscribe to events, like marker clicks, using extension functions. The library also supports merging multiple event types, such as various camera events, into a single observable stream using RxJava operators.\n"]]