mirror of
https://github.com/googlemaps/android-samples.git
synced 2025-12-08 18:02:20 +00:00
chore(snippets): Add snippets for Maps Rx. (#902)
* chore(snippets): Add snippets for Maps Rx. Change-Id: I820e3268f3cbe89c34bc63e7b4a55897b70c6ec4 * Fix ending tag. Change-Id: Ie6b0628292b98fc497817e41944a4000f428b6df
This commit is contained in:
parent
fb86d48e5b
commit
3583e62061
@ -10,7 +10,7 @@ android {
|
||||
compileSdk 32
|
||||
defaultConfig {
|
||||
applicationId "com.google.maps.example"
|
||||
minSdk 21
|
||||
minSdk 24
|
||||
targetSdk 32
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
@ -61,15 +61,19 @@ dependencies {
|
||||
implementation "androidx.compose.material:material:1.2.0-alpha05"
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
implementation 'androidx.navigation:navigation-fragment:2.4.1'
|
||||
implementation 'androidx.navigation:navigation-ui:2.4.1'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
|
||||
implementation 'com.android.volley:volley:1.2.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
|
||||
implementation 'io.reactivex.rxjava3:rxjava:3.1.4'
|
||||
implementation 'com.google.android.libraries.places:places:2.5.0'
|
||||
|
||||
gmsImplementation 'com.google.maps.android:maps-ktx:3.3.0'
|
||||
gmsImplementation 'com.google.maps.android:maps-compose:2.0.0'
|
||||
gmsImplementation 'com.google.android.gms:play-services-maps:18.0.2'
|
||||
gmsImplementation 'com.google.maps.android:android-maps-utils:2.3.0'
|
||||
gmsImplementation 'com.google.maps.android:maps-rx:0.2.0'
|
||||
gmsImplementation 'com.google.maps.android:places-rx:0.2.0'
|
||||
v3Implementation 'com.google.android.libraries.maps:maps:3.1.0-beta'
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
package com.google.maps.example.kotlin
|
||||
|
||||
import android.util.Log
|
||||
import com.google.android.gms.maps.GoogleMap
|
||||
import com.google.maps.android.rx.cameraIdleEvents
|
||||
import com.google.maps.android.rx.cameraMoveCanceledEvents
|
||||
import com.google.maps.android.rx.cameraMoveEvents
|
||||
import com.google.maps.android.rx.cameraMoveStartedEvents
|
||||
import com.google.maps.android.rx.markerClickEvents
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
|
||||
internal class MapsRx {
|
||||
private fun markerClicks(googleMap: GoogleMap) {
|
||||
// [START maps_android_maps_rx_marker_click_events]
|
||||
googleMap.markerClickEvents()
|
||||
.subscribe { marker ->
|
||||
Log.d("MapsRx", "Marker ${marker.title} was clicked")
|
||||
}
|
||||
// [END maps_android_maps_rx_marker_click_events]
|
||||
}
|
||||
|
||||
private fun cameraEvents(googleMap: GoogleMap) {
|
||||
// [START maps_android_maps_rx_camera_merge_events]
|
||||
Observable.merge(
|
||||
googleMap.cameraIdleEvents(),
|
||||
googleMap.cameraMoveEvents(),
|
||||
googleMap.cameraMoveCanceledEvents(),
|
||||
googleMap.cameraMoveStartedEvents()
|
||||
).subscribe {
|
||||
// Notified when any camera event occurs
|
||||
}
|
||||
// [END maps_android_maps_rx_camera_merge_events]
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package com.google.maps.example.kotlin
|
||||
|
||||
import android.util.Log
|
||||
import com.google.android.libraries.places.api.model.Place
|
||||
import com.google.android.libraries.places.api.net.PlacesClient
|
||||
import com.google.maps.android.rx.places.fetchPlace
|
||||
|
||||
internal class PlacesRx {
|
||||
fun fetchPlace(placesClient: PlacesClient) {
|
||||
// [START maps_android_places_rx_marker_click_events]
|
||||
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}")
|
||||
}
|
||||
)
|
||||
}
|
||||
// [END maps_android_places_rx_marker_click_events]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user