Skip to content
المشاريع

giorgiabosello/google-maps-react-markers

عرض على GitHub

حول

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.

تطوير الويب والتطبيقات

كيف تُقاس هذه الأرقام

ما يمكنك فعله

  • 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.

النمو المقاس للنجوم

خلال 24 ساعة
٠
خلال 7 أيام
٠
خلال 15 يومًا
جارٍ جمع السجل
خلال شهر
جارٍ جمع السجل

تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.

README.md

الأصل

Google Maps React Markers

npm version npm downloads bundle size CI MIT license

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 (react and react-dom are 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. 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.
  • Accessible. Clickable and draggable markers are keyboard buttons with screen reader names and announcements, on both renderers.
  • SSR and React Server Components. No window during 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-loader included, 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

استكشف مشاريع مشابهة ومرتبطة

جارٍ التحميل…