{"id":29880368,"url":"https://github.com/fgnass/googlemaps-react-primitives","last_synced_at":"2025-07-31T09:41:17.496Z","repository":{"id":41876339,"uuid":"455245609","full_name":"fgnass/googlemaps-react-primitives","owner":"fgnass","description":"Google Maps primitives for React","archived":false,"fork":false,"pushed_at":"2023-10-23T14:28:19.000Z","size":562,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-06-23T23:50:32.336Z","etag":null,"topics":["googlemaps","react"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fgnass.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-03T16:40:47.000Z","updated_at":"2023-11-01T10:23:01.000Z","dependencies_parsed_at":"2022-08-11T20:00:44.393Z","dependency_job_id":null,"html_url":"https://github.com/fgnass/googlemaps-react-primitives","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fgnass/googlemaps-react-primitives","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgnass%2Fgooglemaps-react-primitives","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgnass%2Fgooglemaps-react-primitives/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgnass%2Fgooglemaps-react-primitives/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgnass%2Fgooglemaps-react-primitives/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fgnass","download_url":"https://codeload.github.com/fgnass/googlemaps-react-primitives/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgnass%2Fgooglemaps-react-primitives/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268009051,"owners_count":24180449,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["googlemaps","react"],"created_at":"2025-07-31T09:41:16.532Z","updated_at":"2025-07-31T09:41:17.442Z","avatar_url":"https://github.com/fgnass.png","language":"TypeScript","readme":"# googlemaps-react-primitives\n\n📍 Google Maps primitives for React\n\n![screenshot](screenshot.png)\n\n[![Edit googlemaps-react-primitives](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/clever-bush-godk3)\n\n## Rationale\n\nWhen looking for a way to add Google Maps to a React application you'll find [tons](https://www.npmjs.com/package/google-map-react) of [different](https://www.npmjs.com/package/react-google-maps) solutions and [libraries](https://www.npmjs.com/package/@react-google-maps/api).\n\nThe idea behind this module is to stick to [Google's official guide for React](https://developers.google.com/maps/documentation/javascript/react-map) as close as possible and provide the missing bits and pieces.\n\n## Features\n\n- Written in TypeScript\n- Super lightweight\n- Tree shakeable\n- Works with @googlemaps/react-wrapper\n\n# Installation\n\n```\nnpm install @googlemaps/react-wrapper googlemaps-react-primitives\nnpm install -D @types/google.maps\n```\n\n# Usage\n\nThis basic example shows everything that's needed in order to display a Google Map with its default options:\n\n```tsx\nimport { Wrapper, Status } from \"@googlemaps/react-wrapper\";\nimport { GoogleMap } from \"googlemaps-react-primitives\";\n\nfunction renderLoadingStatus(status: Status) {\n  return \u003ch1\u003e{status}\u003c/h1\u003e;\n}\n\nfunction App() {\n  return (\n    \u003cWrapper apiKey=\"YOUR_API_KEY\" render={renderLoadingStatus}\u003e\n      \u003cGoogleMap style={{ width: \"400px\", height: \"400px\" }} /\u003e\n    \u003c/Wrapper\u003e\n  );\n}\n```\n\nTo configure the map you can pass [all supported options](https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions) as props:\n\n```tsx\n\u003cGoogleMap center={{ lat: 53.551086, lng: 9.993682 }} zoom={11} /\u003e\n```\n\n## Map Markers\n\nYou can place standard markers on the map using the `Marker` component. It supports all [marker options](https://developers.google.com/maps/documentation/javascript/reference/marker#MarkerOptions) as props.\n\n```tsx\nimport { GoogleMap, Marker } from \"googlemaps-react-primitives\";\n\nfunction MyMap() {\n  return (\n    \u003cGoogleMap\u003e\n      \u003cMarker position={{ lat: 53.551086, lng: 9.993682 }} /\u003e\n      \u003cMarker position={{ lat: 52.520008, lng: 13.404954 }} /\u003e\n    \u003c/GoogleMap\u003e\n  );\n}\n```\n\nYou can use this primitive to create a customized markers, for example to draw a custom path:\n\n```tsx\nfunction MyMarker(props: google.maps.MarkerOptions) {\n  return (\n    \u003cMarker\n      {...props}\n      icon={{\n        path: \"M9 22C9 22 18 16 18 9C18 4.02944 13.9706 0 9 0C4.02944 0 0 4.02944 0 9C0 16 9 22 9 22ZM12 9C12 10.6569 10.6569 12 9 12C7.34315 12 6 10.6569 6 9C6 7.34315 7.34315 6 9 6C10.6569 6 12 7.34315 12 9Z\",\n        strokeColor: \"#FFFFFF\",\n        fillColor: \"#009A9E\",\n        fillOpacity: 0.8,\n        scale: 1.5,\n        anchor: new google.maps.Point(9, 22),\n      }}\n    /\u003e\n  );\n}\n```\n\nBy default, Google markers can only provide a single SVG path. To allow more complex icons, this library includes a utility component to render complete SVGs:\n\n```tsx\nimport { GoogleMap, SvgMarker } from \"googlemaps-react-primitives\";\n\nfunction MyMap() {\n  return (\n    \u003cGoogleMap\u003e\n      \u003cSvgMarker\n        position={{ lat: 48.864716, lng: 2.349014 }}\n        svg={`\u003csvg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"\u003e\n              \u003cpath fill=\"#e74c3c\" d=\"M12 0a8 8 0 0 0-7 12l7 12 7-12a8 8 0 0 0-7-12zm0 4a4 4 0 1 1 0 8 4 4 0 0 1 0-8z\" /\u003e\n              \u003cpath fill=\"#c0392b\" d=\"M12 3a5 5 0 1 0 0 10 5 5 0 0 0 0-10zm0 2a3 3 0 1 1 0 6 3 3 0 0 1 0-6z\" /\u003e\n            \u003c/svg\u003e`}\n      /\u003e\n    \u003c/GoogleMap\u003e\n  );\n}\n```\n\n## Overlays\n\nYou can render arbitrary React component onto the map by using the `Overlay` component:\n\n```tsx\nimport { GoogleMap, Overlay } from \"googlemaps-react-primitives\";\n\nfunction MyMap() {\n  return (\n    \u003cGoogleMap\u003e\n      \u003cOverlay position={{ lat: 123, lng: 456 }}\u003e\n        \u003cdiv\u003eHello\u003c/div\u003e\n      \u003c/Overlay\u003e\n      \u003cOverlay position={{ lat: 124, lng: 457 }}\u003e\n        \u003cdiv\u003eWorld\u003c/div\u003e\n      \u003c/Overlay\u003e\n    \u003c/GoogleMap\u003e\n  );\n}\n```\n\nAs with custom markers, it makes sense to create your own component that uses the `Overlay` primitive. Note that the overlay content is rendered into an absolutely positioned div and the top-left corner is placed at the given coordinates. You can use a CSS transform to center it horizontally:\n\n```tsx\ninterface Props {\n  position: google.maps.LatLngLiteral;\n  text: string;\n}\n\nfunction MyOverlay({ position, text }: Props) {\n  return (\n    \u003cOverlay position={position} preventMapHits\u003e\n      \u003cdiv style={{ transform: \"translateX(-50%)\" }}\u003e{text}\u003c/div\u003e\n    \u003c/Overlay\u003e\n  );\n}\n```\n\n**Note:** You can pass the `preventMapHits` property to stop clicks etc. from bubbling up to the map.\n\n## Polylines\n\nYou can draw lines on the map using the `\u003cPolyline\u003e` primitive:\n\n```tsx\nimport { GoogleMap, Polyline } from \"googlemaps-react-primitives\";\n\nfunction MyMap() {\n  return (\n    \u003cGoogleMap\u003e\n      \u003cPolyline\n        path={[\n          { lat: 48.137154, lng: 11.576124 },\n          { lat: 48.210033, lng: 16.363449 },\n        ]}\n        strokeColor=\"red\"\n      /\u003e\n    \u003c/GoogleMap\u003e\n  );\n}\n```\n\n## Encoded Polylines\n\nIf you want to draw [encoded](https://developers.google.com/maps/documentation/utilities/polylinealgorithm) polylines, you can use the `\u003cEncodedPolyline /\u003e` primitive.\n\n**NOTE:** Decoding requires the `geometry` library to be loaded:\n\n```tsx\nimport { GoogleMap, EncodedPolyline } from \"googlemaps-react-primitives\";\n\nfunction MyMap() {\n  return (\n    \u003cGoogleMap libraries={[\"geometry\"]}\u003e\n      \u003cEncodedPolyline unescape location=\"ayp_I}cypAgkhElgyS\" /\u003e\n    \u003c/GoogleMap\u003e\n  );\n}\n```\n\n**NOTE:** Polyline strings returned by the Google Directions API contain escaped backslashes. In order to use them directly you can pass the `unescape` prop.\n\n## Auto-fitting the map view\n\nWhen placing markers or overlays on the map you can pass the `autoFit` prop in order to automatically center and zoom the map so that all nested markers and overlays are visible in the initial viewport.\n\n```tsx\nimport { GoogleMap, Marker } from \"googlemaps-react-primitives\";\n\nfunction MyMap() {\n  return (\n    \u003cGoogleMap autoFit maxZoom={14}\u003e\n      \u003cMarker position={{ lat: 123, lng: 456 }} /\u003e\n      \u003cMarker position={{ lat: 124, lng: 457 }} /\u003e\n    \u003c/GoogleMap\u003e\n  );\n}\n```\n\n## Accessing the map instance\n\nWhen you write custom components that need to access the map instance, you can use the `useMap()` hook.\n\n## Viewing the example\n\nWhen you check out the repository you can view the example using the following command:\n\n`VITE_API_KEY=\u003cyourApiKey\u003e npm start`\n\n# License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffgnass%2Fgooglemaps-react-primitives","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffgnass%2Fgooglemaps-react-primitives","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffgnass%2Fgooglemaps-react-primitives/lists"}