From 6ef256924b3a8715d2ad556c47f0f99d80692291 Mon Sep 17 00:00:00 2001 From: Dale Hawkins <107309+dkhawk@users.noreply.github.com> Date: Thu, 25 Jul 2024 08:06:11 -0600 Subject: [PATCH] feat: improves AdvancedMarkers collision comments and snippets (#1716) --- .../AdvancedMarkersCollisionActivity.java | 15 ++++++++------- .../kotlin/AdvancedMarkersCollisionActivity.kt | 16 ++++++++++------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/snippets/app/src/gms/java/com/google/maps/example/AdvancedMarkersCollisionActivity.java b/snippets/app/src/gms/java/com/google/maps/example/AdvancedMarkersCollisionActivity.java index 0b0fc192c..1c8c1b08d 100644 --- a/snippets/app/src/gms/java/com/google/maps/example/AdvancedMarkersCollisionActivity.java +++ b/snippets/app/src/gms/java/com/google/maps/example/AdvancedMarkersCollisionActivity.java @@ -21,7 +21,6 @@ import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.model.AdvancedMarkerOptions; -import com.google.android.gms.maps.model.AdvancedMarkerOptions.CollisionBehavior; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; @@ -33,12 +32,14 @@ class AdvancedMarkersCollisionActivity extends AppCompatActivity { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // [START maps_android_marker_collision] - Marker marker = map.addMarker( - new AdvancedMarkerOptions() - .position(new LatLng(10.0, 10.0)) - .zIndex(10f) // Optional. - .collisionBehavior(CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY) - ); + // Collision behavior can only be changed in the AdvancedMarkerOptions object. + // Changes to collision behavior after a marker has been created are not possible + int collisionBehavior = AdvancedMarkerOptions.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL; + AdvancedMarkerOptions options = new AdvancedMarkerOptions() + .position(new LatLng(10.0, 10.0)) + .collisionBehavior(collisionBehavior); + + Marker marker = map.addMarker(options); // [END maps_android_marker_collision] } } diff --git a/snippets/app/src/gms/java/com/google/maps/example/kotlin/AdvancedMarkersCollisionActivity.kt b/snippets/app/src/gms/java/com/google/maps/example/kotlin/AdvancedMarkersCollisionActivity.kt index 5e20b7ce8..ef8cc42f0 100644 --- a/snippets/app/src/gms/java/com/google/maps/example/kotlin/AdvancedMarkersCollisionActivity.kt +++ b/snippets/app/src/gms/java/com/google/maps/example/kotlin/AdvancedMarkersCollisionActivity.kt @@ -20,6 +20,8 @@ import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.model.AdvancedMarkerOptions import com.google.android.gms.maps.model.AdvancedMarkerOptions.CollisionBehavior import com.google.android.gms.maps.model.LatLng +import com.google.android.gms.maps.model.Marker + class AdvancedMarkersCollisionActivity : AppCompatActivity() { @@ -28,12 +30,14 @@ class AdvancedMarkersCollisionActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // [START maps_android_marker_collision] - val marker = map.addMarker( - AdvancedMarkerOptions() - .position(LatLng(10.0, 10.0)) - .zIndex(10f) // Optional. - .collisionBehavior(CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY) - ) + // Collision behavior can only be changed in the AdvancedMarkerOptions object. + // Changes to collision behavior after a marker has been created are not possible + val collisionBehavior: Int = CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL + val advancedMarkerOptions: AdvancedMarkerOptions = AdvancedMarkerOptions() + .position(LatLng(10.0, 10.0)) + .collisionBehavior(collisionBehavior) + + val marker: Marker = map.addMarker(advancedMarkerOptions) ?: error("Failed to add marker") // [END maps_android_marker_collision] } } \ No newline at end of file