React Google Maps
React component and hooks library for Google Maps
README
[!IMPORTANT]
This project is still in it's alpha phase.
When using it be aware that things may not yet work as expected and can
break at any point. Releases happen often, so when you experience problems,
make sure you are using the latest version (check with npm outdated in
your project) before opening an issue.
We are still in a phase where we can easily make bigger changes, so we ask
you to please provide feedback
on everything you notice - including, but not limited to
- developer experience (installation, typings, sourcemaps, framework integration, ...)
- hard to understand concepts and APIs
- wrong, missing, outdated or inaccurate documentation
- use-cases not covered by the API
- missing features
- and of course any bugs you encounter
Also, feel free to use GitHub discussions to ask questions or start a new
discussion.
React Components for the Google Maps JavaScript API
Installation
- ```sh
- npm install @vis.gl/react-google-maps
- ```
Usage
- ```tsx
- import {APIProvider, Map, Marker} from '@vis.gl/react-google-maps';
- function App() {
- const position = {lat: 53.54992, lng: 10.00678};
- return (
- <APIProvider apiKey={'YOUR API KEY HERE'}>
- <Map center={position} zoom={10}>
- <Marker position={position} />
- </Map>
- </APIProvider>
- );
- }
- export default App;
- ```
Using other libraries of the Maps JavaScript API
- ```tsx
- import {useMapsLibrary} from '@vis.gl/react-google-maps';
- const MyComponent = () => {
- // triggers loading the places library and returns true once complete (the
- // component calling the hook gets automatically re-rendered when this is
- // the case)
- const placesLib = useMapsLibrary('places');
- const [placesService, setPlacesService] = useState(null);
- useEffect(() => {
- if (!placesLib) return;
- setPlacesService(new placesLib.PlacesService());
- }, [placesLib]);
- useEffect(() => {
- if (!placesService) return;
- // ...use placesService...
- }, [placesService]);
- return <></>;
- };
- ```