مكتبة RxJava
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تُعد RxJava مكتبة برمجة تفاعلية لإنشاء برامج غير متزامنة وقائمة على الأحداث من خلال
باستخدام تسلسلات قابلة للملاحظة.
مكتبة Rx للخرائط
تتيح لك تلقّي تسلسلات قابلة للملاحظة للأحداث غير المتزامنة على حزمة تطوير البرامج بالاستناد إلى بيانات "خرائط Google" لنظام التشغيل Android
و Places SDK لنظام التشغيل Android حتى تتمكن من الاستفادة من مجموعة ميزات RxJava الغنية.
تثبيت
لتثبيت مكتبة Rx في "خرائط Google" في مشروعك على "خرائط Google":
أضِف التبعيات التالية إلى ملف 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.2.0")
implementation("com.google.android.libraries.places:places:4.4.1")
implementation("io.reactivex.rxjava3:rxjava:3.1.11")
- أعِد إنشاء مشروعك في "استوديو Android" لمزامنة هذه التغييرات.
مثال على الاستخدام
تلقّي عنصر قابل للملاحظة لأحداث النقر على العلامة كوظيفة إضافة على كائن 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
}
الخطوات التالية
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThe Maps Rx library enables the use of RxJava with the Maps SDK and Places SDK for Android to handle asynchronous events.\u003c/p\u003e\n"],["\u003cp\u003eIt provides observable sequences for events like marker clicks and camera movements, allowing developers to leverage RxJava features.\u003c/p\u003e\n"],["\u003cp\u003eYou can install the library by adding specific dependencies to your \u003ccode\u003ebuild.gradle\u003c/code\u003e file and rebuilding your project.\u003c/p\u003e\n"],["\u003cp\u003eThe library offers extension functions and operators to simplify the integration of RxJava with Google Maps functionality.\u003c/p\u003e\n"]]],["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"],null,["RxJava is a reactive programming library for composing asynchronous and event-based programs by\nusing observable sequences.\n\nThe [Maps Rx library](https://github.com/googlemaps/android-maps-rx)\nlets you receive observable sequences for asynchronus events on the Maps SDK for Android\nand Places SDK for Android so you can take advantage of the rich set of RxJava features.\n\nInstallation **Note:** See the [Maps Rx library](https://github.com/googlemaps/android-maps-rx) documentation on GitHub for the latest system requirements and installation instructions.\n\nTo install the Maps Rx library in your Google Maps project:\n\n1. Add the following dependencies to your module-level `build.gradle` file:\n\n ```yaml\n dependencies {\n // RxJava bindings for the Maps SDK\n implementation(\"com.google.maps.android:maps-rx:1.0.0\")\n\n // RxJava bindings for the Places SDK\n implementation(\"com.google.maps.android:places-rx:1.0.0\")\n\n // It is recommended to also include the latest Maps SDK, Places SDK and RxJava so you\n // have the latest features and bug fixes.\n implementation(\"com.google.android.gms:play-services-maps:19.2.0\")\n implementation(\"com.google.android.libraries.places:places:4.4.1\")\n implementation(\"io.reactivex.rxjava3:rxjava:3.1.11\")\n ```\n2. Rebuild your project in Android Studio to sync these changes.\n\nExample Usage\n\nReceive an Observable for marker click events as an extension function on the GoogleMap object: \n\n```yaml\ngoogleMap.markerClickEvents()\n .subscribe { marker -\u003e\n Log.d(\"MapsRx\", \"Marker ${marker.title} was clicked\")\n }\n```\n\nThe next example shows you how you can use the RxJava operator, `merge`, to combine\nvarious camera events into a single Observable stream: \n\n```yaml\nObservable.merge(\n googleMap.cameraIdleEvents(),\n googleMap.cameraMoveEvents(),\n googleMap.cameraMoveCanceledEvents(),\n googleMap.cameraMoveStartedEvents()\n).subscribe {\n // Notified when any camera event occurs\n}\n```\n\nWhat's next\n\n- View the [Maps Rx library](https://github.com/googlemaps/android-maps-rx) GitHub project page.\n- View the [Maps Rx library API reference](https://googlemaps.github.io/android-maps-rx/)."]]