Socket
Book a DemoInstallSign in
Socket

route-replay-googlemaps-react

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

route-replay-googlemaps-react

React hook and components for route-replay-googlemaps

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

route-replay-googlemaps-react

React hook and components for route-replay-googlemaps.

See the main project documentation for more details.

Installation

npm install route-replay-googlemaps-react route-replay-googlemaps-core react react-dom @types/google.maps
# or
yarn add route-replay-googlemaps-react route-replay-googlemaps-core react react-dom @types/google.maps
# or
pnpm add route-replay-googlemaps-react route-replay-googlemaps-core react react-dom @types/google.maps

Usage

import { RouteReplay, RouteReplayHandle } from 'route-replay-googlemaps-react';
import { useRef, useState, useEffect } from 'react';
import { Loader } from '@googlemaps/js-api-loader';
import type { RouteInput } from 'route-replay-googlemaps-core';

function MyMapComponent() {
  const [mapInstance, setMapInstance] = useState<google.maps.Map | null>(null);
  const replayHandleRef = useRef<RouteReplayHandle>(null);
  const apiKey = 'YOUR_GOOGLE_MAPS_API_KEY';

  useEffect(() => {
    const loader = new Loader({ apiKey, version: 'weekly', libraries: ['maps'] });
    loader.importLibrary("maps").then((google) => {
      const map = new google.Map(document.getElementById("map")!, {
        center: { lat: 35.68, lng: 139.76 },
        zoom: 15,
      });
      setMapInstance(map);
    });
  }, [apiKey]);

  const routeData: RouteInput = [/* your route points */];

  return (
    <div>
      <div id="map" style={{ height: '500px', width: '100%' }} />
      {mapInstance && (
        <RouteReplay
          ref={replayHandleRef}
          map={mapInstance}
          route={routeData}
        />
      )}
      <button onClick={() => replayHandleRef.current?.play()} disabled={!mapInstance}>Play</button>
      <button onClick={() => replayHandleRef.current?.pause()} disabled={!mapInstance}>Pause</button>
    </div>
  );
}

License

ISC

Keywords

google-maps

FAQs

Package last updated on 30 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.