giorgiabosello/google-maps-react-markers
소개
Google Maps for React 19: render any React component as a marker. Advanced markers or custom overlays, drag and drop, clustering-ready, SSR safe and fully typed.
웹 및 앱 개발What you can do
- Any component is a marker. Markers are React portals: state, hooks, context and your CSS all work.
- Two renderers, one API. AdvancedMarkerElement when the map has a mapId, a custom overlay when it does not (so JSON styles keep working).
- Drag and drop with mouse, touch and keyboard, anchor, zIndex and clicks.
- Fast. Markers are created once and updated in place. The stress test renders up to 5,000 markers.
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 기록 수집 중
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Original
Render any React component as a Google Maps marker. React 19, Next.js 16, advanced markers or custom overlays, drag and drop, clustering-ready, SSR safe, fully typed.
Documentation and live demos →
Install
npm i google-maps-react-markers
# or
pnpm add google-maps-react-markers
yarn add google-maps-react-markers
bun add google-maps-react-markers
- React 19 (
reactandreact-domare peer dependencies). - ESM only. Node.js 22.12+ for server rendering and builds.
- A Google Maps Platform API key, restricted to your sites. A map ID is optional: it enables advanced markers.
Works with Next.js (App Router and Server Components), Vite, React Router, TanStack Start and Astro.
Usage
import { GoogleMap, Marker } from 'google-maps-react-markers'
export function StoreMap({ stores, onSelect }) {
return (
<GoogleMap
apiKey="YOUR_API_KEY"
mapId="YOUR_MAP_ID"
defaultCenter={{ lat: 45.44, lng: 12.32 }}
defaultZoom={6}
style={{ height: 480 }}
onChange={({ center, zoom, bbox }) => console.log(center, zoom, bbox)}
>
{stores.map((store) => (
<Marker
key={store.id}
lat={store.lat}
lng={store.lng}
anchor="bottom"
title={`${store.price} at ${store.name}`}
onClick={() => onSelect(store.id)}
>
<PriceTag price={store.price} />
</Marker>
))}
</GoogleMap>
)
}
Features
- Any component is a marker. Markers are React portals: state, hooks, context and your CSS all work.
- Two renderers, one API.
AdvancedMarkerElementwhen the map has amapId, a custom overlay when it does not (so JSONstyleskeep working). - Drag and drop with mouse, touch and keyboard,
anchor,zIndexand clicks. - Fast. Markers are created once and updated in place. The stress test renders up to 5,000 markers.
- Accessible. Clickable and draggable markers are keyboard buttons with screen reader names and announcements, on both renderers.
- SSR and React Server Components. No
windowduring render, clean hydration,'use client'included. - Hooks and controls.
useMap(),useMapsLibrary(),useGoogleMapsStatus(),<MapControl>. - Small and typed. About 6 kB brotli with the official
@googlemaps/js-api-loaderincluded, ESM only.
Upgrading from v2
v3 is a breaking release: markers go inside <Marker>, the import is named, and a few props changed. Follow the migration guide.
Contributing
See CONTRIBUTING.md.
Support
If this library saves you time, you can buy me a coffee or send a PayPal tip.
License
MIT © Giorgia Bosello
관련 프로젝트 살펴보기
불러오는 중…