Marker Collision Management

Stay organized with collections Save and categorize content based on your preferences.

Handle marker collisions

Vector maps provide basic support for marker collision. For example, you can modify the marker API to hide labels. Vector maps also provide support for prioritization of markers.

The following example always displays markers and hides underlying labels:

var marker = new google.maps.Marker({
  position: event.latLng,
  map: map,
  collisionBehavior:
    google.maps.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL,
  });

The following example hides markers if they collide with a required marker and hides underlying labels:

var marker = new google.maps.Marker({
  position: event.latLng,
  map: map,
  collisionBehavior:
    google.maps.CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY,
  });

Try Sample

Clone Sample

Git and Node.js are required to run this sample locally. Follow these instructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.

  git clone -b sample-marker-collision-management https://github.com/googlemaps/js-samples.git
  cd js-samples
  npm i
  npm start

Other samples can be tried by switching to any branch beginning with sample-SAMPLE_NAME.

  git checkout sample-SAMPLE_NAME
  npm i
  npm start