---
title: "Example: Marker Clustering · Nuxt Scripts"
description: "Group dense sets of Google Maps markers with the marker clusterer component."
canonical_url: "https://scripts.nuxt.com/scripts/google-maps/guides/marker-clustering"
meta:
  "og:description": "Group dense sets of Google Maps markers with the marker clusterer component."
  "og:image": "https://scripts.nuxt.com/_og/s/o_4bb3c27cb0ffbf40.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Example: Marker Clustering · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_4bb3c27cb0ffbf40.png"
---

> Index of every page on this site: [llms.txt](https://scripts.nuxt.com/llms.txt)

**Guides**

# **Example: Marker Clustering**

[Copy for LLMs](https://scripts.nuxt.com/scripts/google-maps/guides/marker-clustering.md)

**Marker Clustering Demo**

Zoom out to see markers group into clusters. Zoom in or click a cluster to expand.

`**ScriptGoogleMapsMarkerClusterer**` wraps the official [`**@googlemaps/markerclusterer**`** library**](https://googlemaps.github.io/js-markerclusterer/), grouping nearby markers into clusters at lower zoom levels.

## Installation

Requires the `**@googlemaps/markerclusterer**` peer dependency:

```bash
pnpm add @googlemaps/markerclusterer
```

## Basic Clustering

Child markers register and unregister themselves automatically.

```vue
<script setup lang="ts">
const locations = [
  { id: 1, position: { lat: -33.8568, lng: 151.2153 }, name: 'Opera House' },
  { id: 2, position: { lat: -33.8688, lng: 151.2093 }, name: 'Town Hall' },
  { id: 3, position: { lat: -33.8708, lng: 151.2073 }, name: 'QVB' },
  { id: 4, position: { lat: -33.8615, lng: 151.2055 }, name: 'Barangaroo' },
  { id: 5, position: { lat: -33.8523, lng: 151.2108 }, name: 'Circular Quay' },
  { id: 6, position: { lat: -33.8750, lng: 151.2050 }, name: 'Darling Harbour' },
]
</script>

<template>
  <ScriptGoogleMaps
    :map-options="{
      center: { lat: -33.863, lng: 151.210 },
      zoom: 14,
    }"
  >
    <ScriptGoogleMapsMarkerClusterer>
      <ScriptGoogleMapsMarker
        v-for="loc in locations"
        :key="loc.id"
        :position="loc.position"
      />
    </ScriptGoogleMapsMarkerClusterer>
  </ScriptGoogleMaps>
</template>
```

## Clustering with Info Windows

Combine clustering with info windows so users can click individual markers once they zoom in.

```vue
<script setup lang="ts">
const locations = [
  {
    id: 1,
    position: { lat: -33.8568, lng: 151.2153 },
    name: 'Opera House',
    description: 'World-famous performing arts center',
  },
  {
    id: 2,
    position: { lat: -33.8688, lng: 151.2093 },
    name: 'Town Hall',
    description: 'Historic civic building',
  },
  {
    id: 3,
    position: { lat: -33.8708, lng: 151.2073 },
    name: 'QVB',
    description: 'Romanesque Revival shopping arcade',
  },
  {
    id: 4,
    position: { lat: -33.8615, lng: 151.2055 },
    name: 'Barangaroo',
    description: 'Waterfront precinct',
  },
  {
    id: 5,
    position: { lat: -33.8523, lng: 151.2108 },
    name: 'Circular Quay',
    description: 'Ferry terminal and transport hub',
  },
]
</script>

<template>
  <ScriptGoogleMaps
    :map-options="{
      center: { lat: -33.863, lng: 151.210 },
      zoom: 13,
    }"
  >
    <ScriptGoogleMapsMarkerClusterer>
      <ScriptGoogleMapsMarker
        v-for="loc in locations"
        :key="loc.id"
        :position="loc.position"
      >
        <ScriptGoogleMapsInfoWindow>
          <h3>{{ loc.name }}</h3>
          <p>{{ loc.description }}</p>
        </ScriptGoogleMapsInfoWindow>
      </ScriptGoogleMapsMarker>
    </ScriptGoogleMapsMarkerClusterer>
  </ScriptGoogleMaps>
</template>
```

## Custom Cluster Renderer

Use the `**#renderer**` slot to render cluster visuals with a Vue template.

```vue
<template>
  <ScriptGoogleMaps
    :map-options="{
      center: { lat: -33.863, lng: 151.210 },
      zoom: 13,
    }"
  >
    <ScriptGoogleMapsMarkerClusterer>
      <template #renderer="{ cluster }">
        <div
          class="bg-blue-600 text-white rounded-full w-10 h-10 flex items-center justify-center font-bold text-sm shadow-lg"
        >
          {{ cluster.count }}
        </div>
      </template>

      <ScriptGoogleMapsMarker
        v-for="loc in locations"
        :key="loc.id"
        :position="loc.position"
      >
        <ScriptGoogleMapsInfoWindow>
          <strong>{{ loc.name }}</strong>
        </ScriptGoogleMapsInfoWindow>
      </ScriptGoogleMapsMarker>
    </ScriptGoogleMapsMarkerClusterer>
  </ScriptGoogleMaps>
</template>
```

## Clustering with Custom Markers

Custom HTML markers cluster the same way as default pins.

```vue
<script setup lang="ts">
const listings = [
  { id: 1, position: { lat: -33.856, lng: 151.215 }, price: '$850k' },
  { id: 2, position: { lat: -33.860, lng: 151.210 }, price: '$1.2M' },
  { id: 3, position: { lat: -33.865, lng: 151.205 }, price: '$720k' },
  { id: 4, position: { lat: -33.870, lng: 151.208 }, price: '$1.5M' },
  { id: 5, position: { lat: -33.858, lng: 151.220 }, price: '$950k' },
]
</script>

<template>
  <ScriptGoogleMaps
    :map-options="{
      center: { lat: -33.863, lng: 151.212 },
      zoom: 14,
    }"
  >
    <ScriptGoogleMapsMarkerClusterer>
      <ScriptGoogleMapsMarker
        v-for="listing in listings"
        :key="listing.id"
        :position="listing.position"
      >
        <template #content>
          <div class="bg-blue-600 text-white px-2.5 py-1 rounded-full font-bold text-sm">
            {{ listing.price }}
          </div>
        </template>
      </ScriptGoogleMapsMarker>
    </ScriptGoogleMapsMarkerClusterer>
  </ScriptGoogleMaps>
</template>
```

[Edit this page](https://github.com/nuxt/scripts/edit/main/docs/content/google-maps/1.guides/6.marker-clustering.md)

[Markdown For LLMs](https://scripts.nuxt.com/scripts/google-maps/guides/marker-clustering.md)

[**Example: Shapes & Overlays** Draw circles, polygons, polylines, rectangles, and GeoJSON data on a Google map.](https://scripts.nuxt.com/scripts/google-maps/guides/shapes-and-overlays) [**Billing & Permissions** Enable the Google Maps APIs you use and estimate their effect on billing.](https://scripts.nuxt.com/scripts/google-maps/guides/billing)

**On this page **

- [Installation](#installation)
- [Basic Clustering](#basic-clustering)
- [Clustering with Info Windows](#clustering-with-info-windows)
- [Custom Cluster Renderer](#custom-cluster-renderer)
- [Clustering with Custom Markers](#clustering-with-custom-markers)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://scripts.nuxt.com/#website","@type":"WebSite","description":"Nuxt Scripts lets you load third-party scripts with better performance, privacy, security and DX. It includes many popular third-parties out of the box.","name":"Nuxt Scripts","url":"https://scripts.nuxt.com/","publisher":{"@id":"https://scripts.nuxt.com/#identity"}},{"@id":"https://scripts.nuxt.com/scripts/google-maps/guides/marker-clustering#webpage","@type":"WebPage","description":"Group dense sets of Google Maps markers with the marker clusterer component.","name":"Example: Marker Clustering","url":"https://scripts.nuxt.com/scripts/google-maps/guides/marker-clustering","breadcrumb":{"@id":"https://scripts.nuxt.com/scripts/google-maps/guides/marker-clustering#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/scripts/google-maps/guides/marker-clustering"]}],"primaryImageOfPage":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/#identity","@type":"Organization","name":"Nuxt Scripts","url":"https://scripts.nuxt.com","logo":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/scripts/google-maps/guides/marker-clustering#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Scripts","item":"https://scripts.nuxt.com/scripts","position":2},{"@type":"ListItem","name":"Google Maps","item":"https://scripts.nuxt.com/scripts/google-maps","position":3},{"@type":"ListItem","name":"Guides","item":"https://scripts.nuxt.com/scripts/google-maps/guides","position":4},{"@type":"ListItem","name":"Example: Marker Clustering","item":"https://scripts.nuxt.com/scripts/google-maps/guides/marker-clustering","position":5}]},{"@id":"https://scripts.nuxt.com/#logo","@type":"ImageObject","caption":"Nuxt Scripts","contentUrl":"https://scripts.nuxt.com/logo.svg","inLanguage":"en","url":"https://scripts.nuxt.com/logo.svg"}]}
```

## Sitemap

See the full [sitemap](https://scripts.nuxt.com/sitemap.md) for all pages.
