Examples and framework integrations
The examples are small, runnable applications that show how the library connects React UI to Google Maps features and related services. They serve as user guides, reusable patterns, and a practical check that new library behavior works in a real application.
Example purpose
Feature examples
Each example focuses on one map task or one group of related tasks. This keeps the main idea visible while showing how map state, user actions, and application UI work together. The set ranges from a first map and marker display to geometry editing, route display, clustering, places search, static maps, and 3D views.
The examples are also intended as starting points for users. A developer can run one as a standalone application, copy its focused components, or open its hosted playground to test the behavior before adding it to a larger product.
References: examples/README.md• L1-19 docs/…/writing-examples.md• L3-17 docs/…/writing-examples.md• L19-38
Feature groups
The feature examples show the main ways an application can present and control map content:
| Feature group | User-facing idea | Example areas |
|---|---|---|
| Map content | Display markers, advanced markers, info windows, shapes, and map controls | basic-map, markers-and-infowindows, advanced-marker, geometry, map-control |
| Data and interaction | Load data, filter it, edit it, cluster it, and respond to selection | marker-clustering, custom-marker-clustering, worker-marker-clustering, drawing, terra-draw |
| Google services | Add places search, autocomplete, directions, and route results to a map | autocomplete, places-ui-kit, directions, routes-api |
| Map modes | Use static maps or a 3D camera with 3D map content and minimap views | static-map, map-3d, map-3d-routes, places-ui-kit-3d |
The examples do not define separate product systems. Together, they show how a product can combine a map with its own controls, data source, and application state.
References: examples/…/app.tsx• L10-19 examples/…/app.tsx• L20-91 examples/…/app.tsx• L21-70 examples/…/app.tsx• L19-53 examples/…/app.tsx• L44-177 examples/…/app.tsx• L11-29 examples/…/app.tsx• L30-65 examples/…/estimate-camera-position.ts• L6-25
External overlays
Overlay composition
An overlay is visual or interactive content placed on top of a map. The examples show that the map can remain the geographic base while another system supplies data rendering or drawing behavior.
The deck.gl examples place GeoJSON and heatmap data on the map through a Google Maps overlay. The Terra Draw example adds a drawing surface and toolbar. These patterns let an application keep map navigation and application controls together while using a specialist tool for a focused task.
This flow shows how map context, external data, and an overlay become one user view.
flowchart LR
A[Application data] --> B[Overlay or drawing tool]
C[Google map] --> B
B --> D[Interactive map view]
D --> E[Application selection or edit state]
The overlay examples are related to map overlays. Read that page for the wider model of content that shares a map with the library.
References: examples/…/app.tsx• L18-39 examples/…/app.tsx• L13-47 examples/…/app.tsx• L19-42 examples/…/README.md• L1-5 examples/…/package.json• L4-16
Google Maps libraries
Service loading
Google Maps JavaScript API libraries are optional services that add capabilities such as routes, places, or geometry. The examples treat them as data sources for React components rather than as separate map views.
The useMapsLibrary hook loads a requested service and makes it available when loading finishes. The directions, Places UI Kit, autocomplete, and 3D route examples then combine that service with the map instance and application state. This pattern keeps service work beside the feature that uses it and allows the UI to wait for the service without assuming that it is ready at first render.
The map runtime page explains the shared provider and map lifecycle. The Google Maps API interaction guide explains the service-loading model in more detail.
References: examples/…/app.tsx• L15-30 examples/…/app.tsx• L39-120 examples/…/app.tsx• L44-135 examples/…/app.tsx• L20-50 examples/…/app.tsx• L17-66 docs/…/interacting-with-google-maps-api.md• L7-13 docs/…/interacting-with-google-maps-api.md• L95-136
Service-backed features
The examples cover two kinds of service use. Some services return map content such as routes or place results. Others supply calculations or UI elements that help the user search, filter, or understand that content.
| Service role | Example behavior |
|---|---|
| Search and place data | Find a place, limit nearby results to the visible area, and show selected place details |
| Route data | Request a route, show its path and waypoints, and fit the map to the result |
| Geometry support | Use map geometry to shape a search area or edit a map shape |
| Google web components | Add Places UI Kit elements beside React map components |
These examples are useful when a product needs more than map display. They show the boundary between the map view, a Google service, and the product's own state.
References: examples/…/app.tsx• L61-149 examples/…/app.tsx• L16-59 examples/…/app.tsx• L10-16 examples/…/README.md• L5-10 examples/…/app.tsx• L12-18 examples/…/package.json• L4-15
Framework integration
Client-only rendering
The Maps JavaScript API needs a browser. Framework applications must therefore keep interactive map work on the client instead of trying to render the map on the server.
The Next.js example marks the map page as a client component and reads its public API key at runtime. Its package scripts also select a sandbox or local TypeScript configuration before starting or building the app. The framework guide describes the same boundary for Next.js and shows a client-only wrapper pattern for Remix. A fallback should preserve the map's final size when a framework renders a loading state so the page does not move when the map starts.
References: examples/…/page.tsx• L1-24 examples/…/layout.tsx• L13-31 examples/…/package.json• L3-20 examples/…/README.md• L1-39 docs/…/ssr-and-frameworks.md• L3-15 docs/…/ssr-and-frameworks.md• L39-73
API loading migration
The wrapper migration example shows how an application that used @googlemaps/react-wrapper can preserve a loading status view while moving to APIProvider. The important integration boundary is the same: the application waits for the Maps API before it renders map-dependent children, then maps library loading states to the application's loading, success, and failure states.
This pattern helps teams migrate without changing the user-facing loading contract all at once. It also shows that the provider can be the shared entry point for both map components and custom loading behavior.
References: examples/…/app.tsx• L11-18 examples/…/wrapper.tsx• L10-55 examples/…/README.md• L1-5
Example lifecycle
Standalone applications
Each normal example is a small application with its own package and development server. It can run with the published library package or with the checked-out library source, which makes the same user scenario useful for both learning and development.
The examples use a Google Maps Platform API key supplied outside the repository. The key is needed for local map use and is not included in the examples. Hosted playgrounds provide a separate place to run the same scenario.
References: examples/README.md• L3-16 examples/…/README.md• L7-35 examples/…/package.json• L1-15 examples/…/package.json• L5-18 examples/…/package.json• L4-15 examples/…/package.json• L4-17 examples/…/README.md• L9-39
Build and typecheck workflows
Example validation has two broad checks. The build workflow compiles each runnable example, while the typecheck workflow checks each example that has a TypeScript project configuration. A separate local-build workflow covers examples that can build against the checked-out library source.
See example validation workflows for the local build and typecheck steps. This page focuses on what the examples demonstrate; that child page focuses on how to validate them.
References: scripts/build-examples.sh• L3-20 scripts/typecheck-examples.sh• L3-22 scripts/build-examples-local.sh• L3-35
Change checklist
When these files or sections are changed, remember to consider these:
- A new example must remain usable with both the published package and the local-library path if it is included in local validation.
- A framework example must keep its client boundary and its public API-key name aligned with the framework's build and runtime rules.
- An example that adds a Google service or external overlay must keep its required API library, package dependency, and loading path aligned.
- A new example must be linked from the example index or site navigation if users are expected to discover it through the hosted examples.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A map is rendered during server-side rendering | The framework cannot create the browser-only Maps JavaScript API view | Keep map code in a client-only boundary or use the framework's client-only wrapper |
| A required API key or Google service is not enabled | The example cannot load the map or the service-backed feature | Supply the example's API-key variable and enable the required Google API before local use |
| A service result arrives after the map or overlay has changed | Old route or overlay content can remain visible or update the wrong view | Clear prior content and guard async work with the current map and request state |
| An example is omitted from a shared build or typecheck path | A broken example can reach users without validation | Use example validation workflows when adding or changing an example |
Key files
| File | Why to read it |
|---|---|
| examples/README.md | Explains the purpose, standalone use, local-library mode, and hosted playgrounds. |
| docs/…/writing-examples.md | Defines the scope and role of examples as user patterns and end-to-end checks. |
| examples/…/app.tsx | Shows the smallest provider-to-map application shape. |
| examples/…/app.tsx | Shows the range of common marker and info window interactions. |
| examples/…/app.tsx | Shows an external data renderer sharing the map view. |
| examples/…/app.tsx | Shows an external drawing tool and map control working together. |
| examples/…/app.tsx | Shows a Google Maps library loaded for a service-backed feature. |
| examples/…/estimate-camera-position.ts | Shows the 3D example's camera-position support for a minimap view. |
| examples/…/page.tsx | Shows the client boundary for a framework application. |
| examples/…/package.json | Shows the separate sandbox and local build paths for the Next.js example. |
| examples/…/package.json | Shows the 3D example's published and local build paths and its geographic helper dependencies. |
| examples/…/wrapper.tsx | Shows the loading-state contract during migration from another provider wrapper. |
| scripts/build-examples.sh | Defines the broad example build pass. |
| scripts/typecheck-examples.sh | Defines the TypeScript validation pass. |