Skip to content

Commit

Permalink
feat: improves AdvancedMarkers collision comments and snippets (#1716)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhawk authored Jul 25, 2024
1 parent abcc8b5 commit 6ef2569
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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]
}
}

0 comments on commit 6ef2569

Please sign in to comment.