{"id":"6b09417d5ce40d447918f2ad","slug":"google-maps","title":"Google Maps in React – API key, Map ID, geolocation, place search, pins and cost control","summary":"A complete Google Maps integration for a React app with the official @vis.gl/react-google-maps library – from a restricted API key and a Map ID, through geolocation, address autocomplete (Places API New) and geocoding, to AdvancedMarker pins, info windows, clustering, fitting bounds and keeping costs under control.","servedLang":"en","availableLangs":["pl","en"],"topics":["google-maps","react"],"techs":["typescript","javascript"],"tags":["google-maps","vis-gl","react-google-maps","advanced-markers","places-api","geocoding","geolocation","markerclusterer","maps-api-key"],"level":"intermediate","kind":"tutorial","access":"members","status":"published","cover":null,"author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"readingMinutes":27,"stats":{"views":2,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-27T08:38:21.447Z","updatedAt":"2026-11-27T13:03:15.174Z","requestedLang":"en","theme":{"hero":"classic","heroMedia":null,"accent":"indigo","background":"grid","weaveResources":true,"toc":"right"},"seoDescription":"Google Maps in React step by step – @vis.gl/react-google-maps (APIProvider, Map, AdvancedMarker, Pin, InfoWindow), API key with HTTP referrer restriction, Map ID, geolocation, PlaceAutocompleteElement, Geocoder, @googlemaps/markerclusterer, fitBounds, performance with thousands of points and Google ","wordCount":5332,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"A map with pins looks like a one-afternoon feature: paste a script, add a key, done. Then the questions arrive: why did someone burn through our key's quota, why are the pins \"deprecated\", how do you show 400 points without freezing a phone, and where did the invoice come from when it \"was supposed to be free\". In this guide you'll build a restaurant finder for a dumpling shop chain in React and work through all of those topics one by one."}]},{"type":"callout","attrs":{"variant":"info","title":"In short"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"@vis.gl/react-google-maps","marks":[{"type":"code"}]},{"type":"text","text":" is the React library for the Maps JavaScript API recommended by Google, built by the vis.gl team with Google Maps Platform's support. "},{"type":"text","text":"APIProvider","marks":[{"type":"code"}]},{"type":"text","text":" loads the API once, "},{"type":"text","text":"Map","marks":[{"type":"code"}]},{"type":"text","text":" creates the map, and "},{"type":"text","text":"AdvancedMarker","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"Pin","marks":[{"type":"code"}]},{"type":"text","text":" and "},{"type":"text","text":"InfoWindow","marks":[{"type":"code"}]},{"type":"text","text":" are ordinary components."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"A browser key is public by definition","marks":[{"type":"bold"}]},{"type":"text","text":" – security comes from restrictions (HTTP referrer + API list), daily quotas and budget alerts, not from hiding the key."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Pins are Advanced Markers now","marks":[{"type":"bold"}]},{"type":"text","text":" (they need a Map ID). With hundreds of points you cluster them ("},{"type":"text","text":"@googlemaps/markerclusterer","marks":[{"type":"code"}]},{"type":"text","text":"); with thousands you also render only what's in view – details in the "},{"type":"text","text":"pins article","marks":[{"type":"link","attrs":{"href":"/en/articles/google-maps-markers"}}]},{"type":"text","text":"."}]}]}]}]},{"type":"callout","attrs":{"variant":"tip","title":"What you'll build"},"content":[{"type":"paragraph","content":[{"type":"text","text":"A \"Find your nearest Pierogarnia\" app in Vite + React 19: a list of 12 restaurants in the Tricity area synced with the map, pins coloured by whether a restaurant delivers, an info window on click, a \"Use my location\" button with a custom marker and an accuracy circle, address search with autocomplete, sorting by distance, the user's address from reverse geocoding, and 400 parcel lockers in clusters. The map is created only when its container comes into view. The code (24 files) downloads as a ZIP from the icon next to the article – just add your own key in "},{"type":"text","text":".env.local","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]},{"type":"paragraph","content":[{"type":"text","text":"Prerequisites:","marks":[{"type":"bold"}]},{"type":"text","text":" a Google Cloud account with a billing account attached (required even within the free caps), Node.js 22+, React with hooks and TypeScript (see the "},{"type":"text","text":"React guide","marks":[{"type":"link","attrs":{"href":"/en/articles/react"}}]},{"type":"text","text":")."}]},{"type":"stats","attrs":{"items":[{"value":"10,000","label":"free map loads per month","hint":"Dynamic Maps SKU (Essentials)"},{"value":"3","label":"APIs to enable","hint":"Maps JavaScript, Places (New), Geocoding"},{"value":"1","label":"APIProvider","hint":"the API loads once for the whole app"},{"value":"400","label":"clustered points","hint":"without janky scrolling"}]}},{"type":"heading","attrs":{"level":2,"id":"step-1-google-cloud-api-key-restrictions-and-map-id"},"content":[{"type":"text","text":"Step 1. Google Cloud: API key, restrictions and Map ID"}]},{"type":"orderedList","attrs":{"start":1},"content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"In the "},{"type":"text","text":"Google Cloud Console","marks":[{"type":"link","attrs":{"href":"https://console.cloud.google.com/"}}]},{"type":"text","text":" create a project and attach a billing account."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"In "},{"type":"text","text":"APIs & Services → Library","marks":[{"type":"bold"}]},{"type":"text","text":" enable "},{"type":"text","text":"Maps JavaScript API","marks":[{"type":"bold"}]},{"type":"text","text":", "},{"type":"text","text":"Places API (New)","marks":[{"type":"bold"}]},{"type":"text","text":" and "},{"type":"text","text":"Geocoding API","marks":[{"type":"bold"}]},{"type":"text","text":"."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"In "},{"type":"text","text":"Keys & Credentials","marks":[{"type":"bold"}]},{"type":"text","text":" create an API key and restrict it straight away:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Application restrictions → Websites (HTTP referrers)","marks":[{"type":"bold"}]},{"type":"text","text":": list the addresses the key may be used from."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"API restrictions → Restrict key","marks":[{"type":"bold"}]},{"type":"text","text":": tick only the three APIs from step 2."}]}]}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"In "},{"type":"text","text":"Map management","marks":[{"type":"bold"}]},{"type":"text","text":" create a JavaScript "},{"type":"text","text":"Map ID","marks":[{"type":"bold"}]},{"type":"text","text":" (vector, ideally). Without a Map ID, Advanced Markers and cloud-based map styling don't work. Locally you can start with "},{"type":"text","text":"DEMO_MAP_ID","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Environment"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"HTTP referrer restriction"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Notes"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"local"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"http://localhost:5173/*","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"a separate development key with a low daily quota"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"staging"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"https://staging.pierogarnia.example/*","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"a separate key – easy to disable without touching production"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"production"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"https://pierogarnia.example/*","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"https://www.pierogarnia.example/*","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"production domains only, daily quotas and a budget alert"}]}]}]}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"sequenceDiagram\n  participant B as Browser (pierogarnia.example)\n  participant G as Google Maps Platform\n  participant X as Another site (stolen key)\n  B->>G: maps/api/js?key=AIza... (Referer: https://pierogarnia.example/)\n  G-->>B: OK – referrer allowed, API allowed\n  B->>G: Geocoder.geocode() with the same key\n  G-->>B: OK – Geocoding API is on the key's API list\n  X->>G: maps/api/js?key=AIza... (Referer: https://other.example/)\n  G-->>X: RefererNotAllowedMapError – no map, no cost","caption":"Everyone can see the key, but it only works from your domain and only for selected APIs"}},{"type":"callout","attrs":{"variant":"warning","title":"A browser key is not a secret"},"content":[{"type":"paragraph","content":[{"type":"text","text":"The key ends up in JavaScript and anyone can see it in developer tools. Hiding it in environment variables changes nothing – the protection is the "},{"type":"text","text":"referrer and API restrictions","marks":[{"type":"bold"}]},{"type":"text","text":". Never use an unrestricted key in the browser, or a server key (e.g. for the Routes API called from your backend). For extra protection the Maps JavaScript API supports Firebase App Check ("},{"type":"text","text":"fetchAppCheckToken","marks":[{"type":"code"}]},{"type":"text","text":" on "},{"type":"text","text":"APIProvider","marks":[{"type":"code"}]},{"type":"text","text":")."}]}]},{"type":"heading","attrs":{"level":2,"id":"step-2-project-and-the-first-map"},"content":[{"type":"text","text":"Step 2. Project and the first map"}]},{"type":"codeBlock","attrs":{"language":"bash"},"content":[{"type":"text","text":"npm create vite@latest pierogi-maps -- --template react-ts\ncd pierogi-maps\nnpm install @vis.gl/react-google-maps @googlemaps/markerclusterer zod\nnpm install -D @types/google.maps\ncp .env.example .env.local   # put your key here"}]},{"type":"codeGroup","attrs":{"title":"Configuration, environment variables and styles"},"content":[{"type":"codeBlock","attrs":{"language":"json","filename":"package.json"},"content":[{"type":"text","text":"{\n  \"name\": \"pierogi-maps\",\n  \"private\": true,\n  \"version\": \"0.1.0\",\n  \"type\": \"module\",\n  \"scripts\": {\n    \"dev\": \"vite\",\n    \"build\": \"tsc --noEmit && vite build\",\n    \"preview\": \"vite preview\"\n  },\n  \"dependencies\": {\n    \"@googlemaps/markerclusterer\": \"^2.6.2\",\n    \"@vis.gl/react-google-maps\": \"^1.10.2\",\n    \"react\": \"^19.3.1\",\n    \"react-dom\": \"^19.3.1\",\n    \"zod\": \"^4.6.7\"\n  },\n  \"devDependencies\": {\n    \"@types/google.maps\": \"^3.67.0\",\n    \"@types/react\": \"^19.3.0\",\n    \"@types/react-dom\": \"^19.3.0\",\n    \"@vitejs/plugin-react\": \"^6.3.0\",\n    \"typescript\": \"~7.0.2\",\n    \"vite\": \"^8.4.0\"\n  }\n}"}]},{"type":"codeBlock","attrs":{"language":"json","filename":"tsconfig.json"},"content":[{"type":"text","text":"{\n  \"compilerOptions\": {\n    \"target\": \"es2023\",\n    \"lib\": [\"ES2023\", \"DOM\", \"DOM.Iterable\"],\n    \"module\": \"esnext\",\n    \"moduleResolution\": \"bundler\",\n    \"types\": [\"vite/client\", \"google.maps\"],\n    \"jsx\": \"react-jsx\",\n    \"noEmit\": true,\n    \"allowImportingTsExtensions\": true,\n    \"verbatimModuleSyntax\": true,\n    \"skipLibCheck\": true,\n    \"noUncheckedIndexedAccess\": true\n  },\n  \"include\": [\"src\", \"vite.config.ts\"]\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"vite.config.ts"},"content":[{"type":"text","text":"import react from \"@vitejs/plugin-react\";\nimport { defineConfig } from \"vite\";\n\nexport default defineConfig({\n  plugins: [react()],\n});"}]},{"type":"codeBlock","attrs":{"language":"bash","filename":".env.example"},"content":[{"type":"text","text":"# Copy to .env.local (never commit it). The browser key is public by design –\n# protect it with HTTP referrer + API restrictions in Google Cloud Console.\nVITE_GOOGLE_MAPS_API_KEY=your-browser-key\n# Map ID from \"Map management\" (needed for Advanced Markers). DEMO_MAP_ID works for local testing.\nVITE_GOOGLE_MAPS_MAP_ID=DEMO_MAP_ID"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"src/env.d.ts"},"content":[{"type":"text","text":"// Typed Vite env variables – a typo in the name becomes a compile error.\ninterface ImportMetaEnv {\n  readonly VITE_GOOGLE_MAPS_API_KEY?: string;\n  readonly VITE_GOOGLE_MAPS_MAP_ID?: string;\n}\n\ninterface ImportMeta {\n  readonly env: ImportMetaEnv;\n}"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"src/config.ts"},"content":[{"type":"text","text":"export const GOOGLE_MAPS_API_KEY = import.meta.env.VITE_GOOGLE_MAPS_API_KEY ?? \"\";\nexport const MAP_ID = import.meta.env.VITE_GOOGLE_MAPS_MAP_ID || \"DEMO_MAP_ID\";\n\n// Tricity (Gdańsk–Sopot–Gdynia) – the default view before data arrives.\nexport const DEFAULT_CENTER: google.maps.LatLngLiteral = { lat: 54.43, lng: 18.57 };"}]},{"type":"codeBlock","attrs":{"language":"html","filename":"index.html"},"content":[{"type":"text","text":"<!doctype html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"UTF-8\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n    <title>Pierogarnia · Find us</title>\n  </head>\n  <body>\n    <div id=\"root\"></div>\n    <script type=\"module\" src=\"/src/main.tsx\"></script>\n  </body>\n</html>"}]},{"type":"codeBlock","attrs":{"language":"css","filename":"src/index.css"},"content":[{"type":"text","text":"* { box-sizing: border-box; }\nbody { margin: 0; font-family: system-ui, sans-serif; color: #1f2328; }\n.layout { display: grid; grid-template-columns: 340px 1fr; height: 100dvh; }\n.sidebar { padding: 16px; overflow-y: auto; border-right: 1px solid #dee2e6; display: grid; gap: 12px; align-content: start; }\n.map { position: relative; }\n.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }\n.list button { width: 100%; text-align: left; padding: 8px 10px; border: 1px solid #dee2e6; border-radius: 8px; background: #fff; cursor: pointer; font: inherit; }\n.list button[aria-current=\"true\"] { border-color: #c2255c; background: #fff0f6; }\n.muted { color: #6c757d; font-size: 0.875rem; }\n.btn { padding: 8px 12px; border-radius: 8px; border: 1px solid #c2255c; background: #c2255c; color: #fff; cursor: pointer; font: inherit; }\n.place-search gmp-place-autocomplete { width: 100%; }\n.you-are-here { width: 18px; height: 18px; border-radius: 50%; background: #1971c2; border: 3px solid #fff; box-shadow: 0 0 0 0 rgba(25, 113, 194, 0.5); animation: pulse 2s infinite; }\n@keyframes pulse { 70% { box-shadow: 0 0 0 14px rgba(25, 113, 194, 0); } 100% { box-shadow: 0 0 0 0 rgba(25, 113, 194, 0); } }\n@media (prefers-reduced-motion: reduce) { .you-are-here { animation: none; } }\n.info h3 { margin: 0 0 4px; font-size: 1rem; }\n.info p { margin: 0; }\n@media (max-width: 720px) { .layout { grid-template-columns: 1fr; grid-template-rows: auto 60dvh; } }"}]}]},{"type":"paragraph","content":[{"type":"text","text":"APIProvider","marks":[{"type":"code"}]},{"type":"text","text":" loads the Maps JavaScript API "},{"type":"text","text":"once","marks":[{"type":"bold"}]},{"type":"text","text":" for the whole app. Extra libraries ("},{"type":"text","text":"marker","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"places","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"geocoding","marks":[{"type":"code"}]},{"type":"text","text":") load on demand when a component needs them. "},{"type":"text","text":"StoreMap","marks":[{"type":"code"}]},{"type":"text","text":" is a thin wrapper around "},{"type":"text","text":"Map","marks":[{"type":"code"}]},{"type":"text","text":" with our defaults:"}]},{"type":"codeGroup","attrs":{"title":"APIProvider and the map component"},"content":[{"type":"codeBlock","attrs":{"language":"typescript","filename":"src/main.tsx"},"content":[{"type":"text","text":"import { APIProvider } from \"@vis.gl/react-google-maps\";\nimport { StrictMode } from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport App from \"./App.tsx\";\nimport { GOOGLE_MAPS_API_KEY } from \"./config.ts\";\nimport \"./index.css\";\n\nconst container = document.getElementById(\"root\");\nif (!container) throw new Error(\"#root element not found\");\n\ncreateRoot(container).render(\n  <StrictMode>\n    {/* Loads the Maps JavaScript API once; libraries (marker, places, geocoding) load on demand. */}\n    <APIProvider\n      apiKey={GOOGLE_MAPS_API_KEY}\n      language=\"pl\"\n      region=\"PL\"\n      onError={(error) => console.error(\"Google Maps failed to load\", error)}\n    >\n      <App />\n    </APIProvider>\n  </StrictMode>,\n);"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"src/map/StoreMap.tsx"},"content":[{"type":"text","text":"import { ColorScheme, Map, type MapProps } from \"@vis.gl/react-google-maps\";\nimport { DEFAULT_CENTER, MAP_ID } from \"../config.ts\";\n\n// A thin wrapper with our defaults; children are markers, info windows and helpers.\nexport function StoreMap({ children, ...props }: MapProps) {\n  return (\n    <Map\n      mapId={MAP_ID} // required for Advanced Markers and cloud-based styling\n      defaultCenter={DEFAULT_CENTER}\n      defaultZoom={11}\n      gestureHandling=\"cooperative\" // ctrl/two-finger zoom: the page still scrolls on mobile\n      disableDefaultUI\n      zoomControl\n      fullscreenControl\n      colorScheme={ColorScheme.FOLLOW_SYSTEM}\n      reuseMaps // keep the map instance when the component remounts (fewer billed map loads)\n      style={{ width: \"100%\", height: \"100%\" }}\n      {...props}\n    >\n      {children}\n    </Map>\n  );\n}"}]}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"defaultCenter","marks":[{"type":"code"}]},{"type":"text","text":" / ","marks":[{"type":"bold"}]},{"type":"text","text":"defaultZoom","marks":[{"type":"code"}]},{"type":"text","text":" are uncontrolled: the map starts there and the user moves it freely afterwards. If you pass "},{"type":"text","text":"center","marks":[{"type":"code"}]},{"type":"text","text":" / "},{"type":"text","text":"zoom","marks":[{"type":"code"}]},{"type":"text","text":", the map becomes controlled, and without handling "},{"type":"text","text":"onCameraChanged","marks":[{"type":"code"}]},{"type":"text","text":" it stops responding to dragging."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"gestureHandling=\"cooperative\"","marks":[{"type":"code"}]},{"type":"text","text":" – on phones, scrolling the page doesn't get \"trapped\" in the map. The map pans with two fingers, and mouse-wheel zoom needs Ctrl."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"colorScheme={ColorScheme.FOLLOW_SYSTEM}","marks":[{"type":"code"}]},{"type":"text","text":" – a light or dark map following the OS setting (works with a Map ID)."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"reuseMaps","marks":[{"type":"code"}]},{"type":"text","text":" – when the component remounts (e.g. navigating back), the library reuses the existing map instance instead of creating a new one. Every new instance is another billed map load."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"step-3-restaurant-data-from-an-api"},"content":[{"type":"text","text":"Step 3. Restaurant data from an API"}]},{"type":"paragraph","content":[{"type":"text","text":"Restaurants come from an API (here: a static "},{"type":"text","text":"public/restaurants.json","marks":[{"type":"code"}]},{"type":"text","text":"). We validate the response with a Zod schema, as in the "},{"type":"text","text":"TypeScript guide","marks":[{"type":"link","attrs":{"href":"/en/articles/typescript"}}]},{"type":"text","text":" – broken coordinates shouldn't take the map down."}]},{"type":"codeGroup","attrs":{"title":"Data and the useRestaurants hook"},"content":[{"type":"codeBlock","attrs":{"language":"json","filename":"public/restaurants.json"},"content":[{"type":"text","text":"[\n  { \"id\": \"oliwa\", \"name\": \"Pierogarnia Oliwa\", \"district\": \"Gdańsk Oliwa\", \"lat\": 54.4103, \"lng\": 18.5605, \"open\": \"11:00–21:00\", \"delivery\": true },\n  { \"id\": \"wrzeszcz\", \"name\": \"Pierogarnia Wrzeszcz\", \"district\": \"Gdańsk Wrzeszcz\", \"lat\": 54.38, \"lng\": 18.606, \"open\": \"11:00–22:00\", \"delivery\": true },\n  { \"id\": \"glowne\", \"name\": \"Pierogarnia Główne Miasto\", \"district\": \"Gdańsk Główne Miasto\", \"lat\": 54.3489, \"lng\": 18.6532, \"open\": \"10:00–23:00\", \"delivery\": false },\n  { \"id\": \"przymorze\", \"name\": \"Pierogarnia Przymorze\", \"district\": \"Gdańsk Przymorze\", \"lat\": 54.404, \"lng\": 18.59, \"open\": \"11:00–21:00\", \"delivery\": true },\n  { \"id\": \"chelm\", \"name\": \"Pierogarnia Chełm\", \"district\": \"Gdańsk Chełm\", \"lat\": 54.334, \"lng\": 18.618, \"open\": \"12:00–20:00\", \"delivery\": true },\n  { \"id\": \"zaspa\", \"name\": \"Pierogarnia Zaspa\", \"district\": \"Gdańsk Zaspa\", \"lat\": 54.3995, \"lng\": 18.6045, \"open\": \"11:00–21:00\", \"delivery\": false },\n  { \"id\": \"sopot\", \"name\": \"Pierogarnia Sopot\", \"district\": \"Sopot Centrum\", \"lat\": 54.4445, \"lng\": 18.5665, \"open\": \"10:00–24:00\", \"delivery\": false },\n  { \"id\": \"orlowo\", \"name\": \"Pierogarnia Orłowo\", \"district\": \"Gdynia Orłowo\", \"lat\": 54.48, \"lng\": 18.563, \"open\": \"11:00–21:00\", \"delivery\": true },\n  { \"id\": \"gdynia\", \"name\": \"Pierogarnia Gdynia Centrum\", \"district\": \"Gdynia Śródmieście\", \"lat\": 54.5189, \"lng\": 18.5305, \"open\": \"10:00–22:00\", \"delivery\": true },\n  { \"id\": \"chylonia\", \"name\": \"Pierogarnia Chylonia\", \"district\": \"Gdynia Chylonia\", \"lat\": 54.544, \"lng\": 18.46, \"open\": \"11:00–20:00\", \"delivery\": true },\n  { \"id\": \"rumia\", \"name\": \"Pierogarnia Rumia\", \"district\": \"Rumia\", \"lat\": 54.571, \"lng\": 18.39, \"open\": \"11:00–20:00\", \"delivery\": false },\n  { \"id\": \"pruszcz\", \"name\": \"Pierogarnia Pruszcz\", \"district\": \"Pruszcz Gdański\", \"lat\": 54.262, \"lng\": 18.636, \"open\": \"11:00–20:00\", \"delivery\": true }\n]"}]},{"type":"codeBlock","attrs":{"language":"typescript","filename":"src/api/restaurants.ts"},"content":[{"type":"text","text":"import { useEffect, useState } from \"react\";\nimport { z } from \"zod\";\n\nconst RestaurantSchema = z.object({\n  id: z.string(),\n  name: z.string(),\n  district: z.string(),\n  lat: z.number().min(-90).max(90),\n  lng: z.number().min(-180).max(180),\n  open: z.string(),\n  delivery: z.boolean(),\n});\nexport type Restaurant = z.infer<typeof RestaurantSchema>;\n\nexport const positionOf = (r: Restaurant): google.maps.LatLngLiteral => ({ lat: r.lat, lng: r.lng });\n\ntype State = { status: \"loading\" } | { status: \"error\"; message: string } | { status: \"ready\"; restaurants: Restaurant[] };\n\n// In a real app this is GET /api/restaurants (or a TanStack Query hook) – the map does not care.\nexport function useRestaurants(): State {\n  const [state, setState] = useState<State>({ status: \"loading\" });\n\n  useEffect(() => {\n    const controller = new AbortController();\n    fetch(\"/restaurants.json\", { signal: controller.signal })\n      .then((res) => (res.ok ? res.json() : Promise.reject(new Error(`HTTP ${res.status}`))))\n      .then((json: unknown) => setState({ status: \"ready\", restaurants: z.array(RestaurantSchema).parse(json) }))\n      .catch((e: unknown) => {\n        if (!controller.signal.aborted) setState({ status: \"error\", message: e instanceof Error ? e.message : String(e) });\n      });\n    return () => controller.abort();\n  }, []);\n\n  return state;\n}"}]}]}]},"toc":[{"id":"step-1-google-cloud-api-key-restrictions-and-map-id","text":"Step 1. Google Cloud: API key, restrictions and Map ID","level":2,"locked":false},{"id":"step-2-project-and-the-first-map","text":"Step 2. Project and the first map","level":2,"locked":false},{"id":"step-3-restaurant-data-from-an-api","text":"Step 3. Restaurant data from an API","level":2,"locked":false},{"id":"step-4-pins-advancedmarker-pin-and-infowindow","text":"Step 4. Pins: AdvancedMarker, Pin and InfoWindow","level":2,"locked":true},{"id":"step-5-geolocation-and-a-custom-html-marker","text":"Step 5. Geolocation and a custom HTML marker","level":2,"locked":true},{"id":"step-6-address-search-and-geocoding","text":"Step 6. Address search and geocoding","level":2,"locked":true},{"id":"step-7-camera-fitting-bounds-and-panning","text":"Step 7. Camera: fitting bounds and panning","level":2,"locked":true},{"id":"step-8-many-markers-and-clustering","text":"Step 8. Many markers and clustering","level":2,"locked":true},{"id":"step-9-putting-the-app-together","text":"Step 9. Putting the app together","level":2,"locked":true},{"id":"performance-with-thousands-of-points","text":"Performance with thousands of points","level":2,"locked":true},{"id":"cost-control","text":"Cost control","level":2,"locked":true},{"id":"common-mistakes","text":"Common mistakes","level":2,"locked":true},{"id":"check-yourself","text":"Check yourself","level":2,"locked":true},{"id":"what-next","text":"What next","level":2,"locked":true}],"locked":true,"paywall":null,"previewRatio":0.3,"totalBlocks":65,"visibleBlocks":19,"resources":[{"id":"6b0857b13c96f2d34d0b32a0","type":"article","provider":"devto","url":"https://dev.to/copilotkit/build-an-ai-travel-planner-with-copilotkit-langgraph-google-maps-api-32fm","embedUrl":null,"title":"🤖 Build an AI Travel Planner with CopilotKit, LangGraph & Google Maps API 🤩","description":"TL;DR In this easy-to-follow tutorial, we’ll take a simple travel planner application and...","author":"Arindam Majumder","thumbnailUrl":"https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkj9fuzgz2pcdnv7v1chq.gif","durationSec":null,"lang":"en","topics":["ai-agents","ai-coding-assistants","ai-in-node"],"techs":["javascript"],"tags":["ai","javascript","webdev","programming"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"devto","publishedAt":"2025-01-16T12:44:01.000Z","popularity":79,"verifiedAt":"2026-11-26T10:54:15.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:49.541Z","updatedAt":"2026-11-26T16:00:49.541Z"},{"id":"6b0857c53c96f2d34d0b47d8","type":"video","provider":"youtube","url":"https://www.youtube.com/watch?v=M4lR_Va97cQ","embedUrl":"https://www.youtube-nocookie.com/embed/M4lR_Va97cQ","title":"FAANG System Design Interview: Design A Location Based Service (Yelp, Google Places)","description":"Weekly system design newsletter: https://bit.ly/3tfAlYD Checkout our bestselling System Design Interview books: Volume 1: https://amzn.to/3Ou7gkd Volume 2: https://amzn.to/3HqGozy Other things we made: Digital version of System Design Interview books: https://bit.ly/3mlDSk9 Twitter…","author":"ByteByteGo","thumbnailUrl":"https://i.ytimg.com/vi/M4lR_Va97cQ/hqdefault.jpg","durationSec":null,"lang":"en","topics":[],"techs":["general"],"tags":["system-design"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"youtube-rss","publishedAt":"2022-07-21T16:15:33.000Z","popularity":86,"verifiedAt":"2026-11-26T10:55:07.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:07.480Z","updatedAt":"2026-11-26T16:01:07.480Z"},{"id":"6b0857b33c96f2d34d0b3640","type":"repo","provider":"github","url":"https://github.com/uber/h3-py","embedUrl":null,"title":"uber/h3-py","description":"Python bindings for H3, a hierarchical hexagonal geospatial indexing system","author":"uber","thumbnailUrl":"https://opengraph.githubassets.com/1/uber/h3-py","durationSec":null,"lang":"en","topics":["hexagonal-architecture"],"techs":["python"],"tags":["geocoding","geospatial","gis","h3","hexagonal-architecture","python","software-architecture","uber"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"github","publishedAt":"2018-06-12T22:39:59.000Z","popularity":58,"verifiedAt":"2026-11-26T10:57:52.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:50.215Z","updatedAt":"2026-11-26T16:00:50.215Z"}],"challenges":[],"attachments":[],"hasCode":true,"repoUrl":null,"series":[],"prev":null,"next":null,"featured":false,"authorCard":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","headline":"Wzorce projektowe · Architektura · AI i LLM","community":false,"reputation":{"points":3900,"level":{"key":"mentor","label":"Mentor"}},"articles":68,"skills":[{"key":"typescript","title":"TypeScript","level":5,"levelLabel":"Authority","articles":63},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Authority","articles":53},{"key":"python","title":"Python","level":5,"levelLabel":"Authority","articles":52},{"key":"java","title":"Java","level":5,"levelLabel":"Authority","articles":38}]}}