{"id":"6b09417d5ce40d447918f2ad","slug":"google-maps","title":"Google Maps w React – klucz API, Map ID, geolokalizacja, wyszukiwarka miejsc, pinezki i kontrola kosztów","summary":"Kompletna integracja Google Maps z aplikacją React przez oficjalną bibliotekę @vis.gl/react-google-maps – od klucza API z ograniczeniami i Map ID, przez geolokalizację, autouzupełnianie adresów (Places API New) i geokodowanie, po pinezki AdvancedMarker, okna informacyjne, klastry, dopasowanie widoku i kontrolę kosztów.","servedLang":"pl","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":26,"stats":{"views":1,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-27T08:38:21.447Z","updatedAt":"2026-11-27T10:03:41.284Z","requestedLang":"pl","theme":{"hero":"classic","heroMedia":null,"accent":"indigo","background":"grid","weaveResources":true,"toc":"right"},"seoDescription":"Google Maps w React krok po kroku – @vis.gl/react-google-maps (APIProvider, Map, AdvancedMarker, Pin, InfoWindow), klucz API z ograniczeniem HTTP referrer, Map ID, geolokalizacja, PlaceAutocompleteElement, Geocoder, @googlemaps/markerclusterer, fitBounds, wydajność przy tysiącach punktów i koszty Go","wordCount":5060,"doc":{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Mapa z pinezkami wygląda na funkcję na jedno popołudnie: wklejasz skrypt, podajesz klucz i gotowe. Potem przychodzą pytania: dlaczego ktoś zużył limit z naszego klucza, czemu pinezki są „przestarzałe”, jak pokazać 400 punktów bez zamrożenia telefonu i skąd faktura, skoro „miało być za darmo”. W tym poradniku zbudujesz wyszukiwarkę lokali sieci pierogarni w React i przejdziesz przez wszystkie te tematy po kolei."}]},{"type":"callout","attrs":{"variant":"info","title":"W skrócie"},"content":[{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"@vis.gl/react-google-maps","marks":[{"type":"code"}]},{"type":"text","text":" to rekomendowana przez Google biblioteka React dla Maps JavaScript API, rozwijana przez zespół vis.gl przy wsparciu Google Maps Platform. "},{"type":"text","text":"APIProvider","marks":[{"type":"code"}]},{"type":"text","text":" ładuje API raz, "},{"type":"text","text":"Map","marks":[{"type":"code"}]},{"type":"text","text":" tworzy mapę, a "},{"type":"text","text":"AdvancedMarker","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"Pin","marks":[{"type":"code"}]},{"type":"text","text":" i "},{"type":"text","text":"InfoWindow","marks":[{"type":"code"}]},{"type":"text","text":" są zwykłymi komponentami."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Klucz przeglądarkowy jest publiczny z definicji","marks":[{"type":"bold"}]},{"type":"text","text":" – bezpieczeństwo zapewniają ograniczenia (HTTP referrer + lista API), limity dzienne i alerty budżetowe, a nie ukrywanie klucza."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Pinezki to dziś Advanced Markers","marks":[{"type":"bold"}]},{"type":"text","text":" (wymagają Map ID). Przy setkach punktów grupujesz je w klastry ("},{"type":"text","text":"@googlemaps/markerclusterer","marks":[{"type":"code"}]},{"type":"text","text":"), przy tysiącach dokładasz renderowanie tylko widocznego fragmentu – szczegóły w "},{"type":"text","text":"artykule o pinezkach","marks":[{"type":"link","attrs":{"href":"/pl/articles/google-maps-markers"}}]},{"type":"text","text":"."}]}]}]}]},{"type":"callout","attrs":{"variant":"tip","title":"Co zbudujesz"},"content":[{"type":"paragraph","content":[{"type":"text","text":"Aplikację „Find your nearest Pierogarnia” w Vite + React 19: lista 12 lokali w Trójmieście zsynchronizowana z mapą, pinezki w kolorach zależnych od tego, czy lokal dowozi, okno informacyjne po kliknięciu, przycisk „Use my location” z niestandardowym znacznikiem i okręgiem dokładności, wyszukiwarka adresów z autouzupełnianiem, sortowanie po odległości, adres użytkownika z geokodowania odwrotnego i 400 paczkomatów w klastrach. Mapa tworzy się dopiero, gdy jej kontener pojawi się na ekranie. Kod (24 pliki) pobierzesz jako ZIP ikoną przy artykule – wystarczy dopisać własny klucz w "},{"type":"text","text":".env.local","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]},{"type":"paragraph","content":[{"type":"text","text":"Wymagania wstępne:","marks":[{"type":"bold"}]},{"type":"text","text":" konto Google Cloud z podpiętym kontem rozliczeniowym (wymagane nawet przy darmowych limitach), Node.js 22+, React z hookami i TypeScript (zob. "},{"type":"text","text":"poradnik React","marks":[{"type":"link","attrs":{"href":"/pl/articles/react"}}]},{"type":"text","text":")."}]},{"type":"stats","attrs":{"items":[{"value":"10 000","label":"darmowych załadowań mapy miesięcznie","hint":"SKU Dynamic Maps (Essentials)"},{"value":"3","label":"API do włączenia","hint":"Maps JavaScript, Places (New), Geocoding"},{"value":"1","label":"APIProvider","hint":"API ładowane raz dla całej aplikacji"},{"value":"400","label":"punktów w klastrach","hint":"bez zacinania przewijania"}]}},{"type":"heading","attrs":{"level":2,"id":"krok-1-google-cloud-klucz-api-ograniczenia-i-map-id"},"content":[{"type":"text","text":"Krok 1. Google Cloud: klucz API, ograniczenia i Map ID"}]},{"type":"orderedList","attrs":{"start":1},"content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"W "},{"type":"text","text":"Google Cloud Console","marks":[{"type":"link","attrs":{"href":"https://console.cloud.google.com/"}}]},{"type":"text","text":" utwórz projekt i podepnij konto rozliczeniowe."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"W "},{"type":"text","text":"APIs & Services → Library","marks":[{"type":"bold"}]},{"type":"text","text":" włącz: "},{"type":"text","text":"Maps JavaScript API","marks":[{"type":"bold"}]},{"type":"text","text":", "},{"type":"text","text":"Places API (New)","marks":[{"type":"bold"}]},{"type":"text","text":" i "},{"type":"text","text":"Geocoding API","marks":[{"type":"bold"}]},{"type":"text","text":"."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"W "},{"type":"text","text":"Keys & Credentials","marks":[{"type":"bold"}]},{"type":"text","text":" utwórz klucz API i od razu go ogranicz:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Application restrictions → Websites (HTTP referrers)","marks":[{"type":"bold"}]},{"type":"text","text":": dopisz adresy, z których klucz może być używany."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"API restrictions → Restrict key","marks":[{"type":"bold"}]},{"type":"text","text":": zaznacz tylko trzy API z punktu 2."}]}]}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"W "},{"type":"text","text":"Map management","marks":[{"type":"bold"}]},{"type":"text","text":" utwórz "},{"type":"text","text":"Map ID","marks":[{"type":"bold"}]},{"type":"text","text":" typu JavaScript (najlepiej wektorowy). Bez Map ID nie działają Advanced Markers ani style mapy w chmurze (cloud-based styling). Lokalnie możesz zacząć od "},{"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":"Środowisko"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Ograniczenie HTTP referrer"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Uwagi"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"lokalnie"}]}]},{"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":"osobny klucz deweloperski z niskim limitem dziennym"}]}]}]},{"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":"osobny klucz – łatwo go wyłączyć bez wpływu na produkcję"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"produkcja"}]}]},{"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":"tylko domeny produkcyjne, limity dzienne i alert budżetowy"}]}]}]}]},{"type":"diagram","attrs":{"kind":"mermaid","code":"sequenceDiagram\n  participant B as Przeglądarka (pierogarnia.example)\n  participant G as Google Maps Platform\n  participant X as Obca strona (kradziony klucz)\n  B->>G: maps/api/js?key=AIza... (Referer: https://pierogarnia.example/)\n  G-->>B: OK – referrer na liście, API dozwolone\n  B->>G: Geocoder.geocode() z tym samym kluczem\n  G-->>B: OK – Geocoding API na liście API klucza\n  X->>G: maps/api/js?key=AIza... (Referer: https://obca.example/)\n  G-->>X: RefererNotAllowedMapError – brak mapy, brak kosztów","caption":"Klucz widzi każdy, ale zadziała tylko z Twojej domeny i tylko dla wybranych API"}},{"type":"callout","attrs":{"variant":"warning","title":"Klucz przeglądarkowy to nie sekret"},"content":[{"type":"paragraph","content":[{"type":"text","text":"Klucz trafia do kodu JavaScript i każdy zobaczy go w narzędziach deweloperskich. Ukrywanie go w zmiennych środowiskowych niczego nie zmienia – ochroną są "},{"type":"text","text":"ograniczenia referrer i API","marks":[{"type":"bold"}]},{"type":"text","text":". Nigdy nie używaj w przeglądarce klucza bez ograniczeń ani klucza serwerowego (np. do Routes API wołanego z backendu). Dla dodatkowej ochrony Maps JavaScript API obsługuje Firebase App Check ("},{"type":"text","text":"fetchAppCheckToken","marks":[{"type":"code"}]},{"type":"text","text":" w "},{"type":"text","text":"APIProvider","marks":[{"type":"code"}]},{"type":"text","text":")."}]}]},{"type":"heading","attrs":{"level":2,"id":"krok-2-projekt-i-pierwsza-mapa"},"content":[{"type":"text","text":"Krok 2. Projekt i pierwsza mapa"}]},{"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   # wpisz swój klucz"}]},{"type":"codeGroup","attrs":{"title":"Konfiguracja, zmienne środowiskowe i style"},"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":" ładuje Maps JavaScript API "},{"type":"text","text":"raz","marks":[{"type":"bold"}]},{"type":"text","text":" dla całej aplikacji. Biblioteki dodatkowe ("},{"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":") doczytują się na żądanie, gdy komponent ich potrzebuje. "},{"type":"text","text":"StoreMap","marks":[{"type":"code"}]},{"type":"text","text":" to cienka nakładka na "},{"type":"text","text":"Map","marks":[{"type":"code"}]},{"type":"text","text":" z naszymi ustawieniami domyślnymi:"}]},{"type":"codeGroup","attrs":{"title":"APIProvider i komponent mapy"},"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":" to tryb niekontrolowany: mapa startuje w tym miejscu, a potem użytkownik przesuwa ją swobodnie. Gdy podasz "},{"type":"text","text":"center","marks":[{"type":"code"}]},{"type":"text","text":" / "},{"type":"text","text":"zoom","marks":[{"type":"code"}]},{"type":"text","text":", mapa staje się kontrolowana i bez obsługi "},{"type":"text","text":"onCameraChanged","marks":[{"type":"code"}]},{"type":"text","text":" przestanie reagować na przeciąganie."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"gestureHandling=\"cooperative\"","marks":[{"type":"code"}]},{"type":"text","text":" – na telefonie przewijanie strony nie „wpada” w mapę. Mapa przesuwa się dwoma palcami, a zoom kółkiem myszy wymaga Ctrl."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"colorScheme={ColorScheme.FOLLOW_SYSTEM}","marks":[{"type":"code"}]},{"type":"text","text":" – jasna lub ciemna mapa zgodnie z ustawieniem systemu (działa z Map ID)."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"reuseMaps","marks":[{"type":"code"}]},{"type":"text","text":" – przy ponownym zamontowaniu komponentu (np. powrót na stronę) biblioteka używa istniejącej instancji mapy zamiast tworzyć nową. Każda nowa instancja to kolejne płatne załadowanie mapy."}]}]}]},{"type":"heading","attrs":{"level":2,"id":"krok-3-dane-lokali-z-api"},"content":[{"type":"text","text":"Krok 3. Dane lokali z API"}]},{"type":"paragraph","content":[{"type":"text","text":"Lokale przychodzą z API (tu: statyczny "},{"type":"text","text":"public/restaurants.json","marks":[{"type":"code"}]},{"type":"text","text":"). Odpowiedź walidujemy schematem Zod, tak jak w "},{"type":"text","text":"poradniku TypeScript","marks":[{"type":"link","attrs":{"href":"/pl/articles/typescript"}}]},{"type":"text","text":" – zepsute współrzędne nie powinny wywrócić mapy."}]},{"type":"codeGroup","attrs":{"title":"Dane i hook useRestaurants"},"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":"krok-1-google-cloud-klucz-api-ograniczenia-i-map-id","text":"Krok 1. Google Cloud: klucz API, ograniczenia i Map ID","level":2,"locked":false},{"id":"krok-2-projekt-i-pierwsza-mapa","text":"Krok 2. Projekt i pierwsza mapa","level":2,"locked":false},{"id":"krok-3-dane-lokali-z-api","text":"Krok 3. Dane lokali z API","level":2,"locked":false},{"id":"krok-4-pinezki-advancedmarker-pin-i-infowindow","text":"Krok 4. Pinezki: AdvancedMarker, Pin i InfoWindow","level":2,"locked":true},{"id":"krok-5-geolokalizacja-i-wlasny-znacznik-html","text":"Krok 5. Geolokalizacja i własny znacznik HTML","level":2,"locked":true},{"id":"krok-6-wyszukiwarka-adresow-i-geokodowanie","text":"Krok 6. Wyszukiwarka adresów i geokodowanie","level":2,"locked":true},{"id":"krok-7-kamera-dopasowanie-widoku-i-przesuwanie","text":"Krok 7. Kamera: dopasowanie widoku i przesuwanie","level":2,"locked":true},{"id":"krok-8-wiele-markerow-i-klastry","text":"Krok 8. Wiele markerów i klastry","level":2,"locked":true},{"id":"krok-9-skladamy-aplikacje","text":"Krok 9. Składamy aplikację","level":2,"locked":true},{"id":"wydajnosc-przy-tysiacach-punktow","text":"Wydajność przy tysiącach punktów","level":2,"locked":true},{"id":"kontrola-kosztow","text":"Kontrola kosztów","level":2,"locked":true},{"id":"typowe-bledy","text":"Typowe błędy","level":2,"locked":true},{"id":"sprawdz-sie","text":"Sprawdź się","level":2,"locked":true},{"id":"co-dalej","text":"Co dalej","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":"Autorytet","articles":63},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Autorytet","articles":53},{"key":"python","title":"Python","level":5,"levelLabel":"Autorytet","articles":52},{"key":"java","title":"Java","level":5,"levelLabel":"Autorytet","articles":38}]}}