Giter Site home page Giter Site logo

erhanaydin / react-google-maps Goto Github PK

View Code? Open in Web Editor NEW

This project forked from visgl/react-google-maps

0.0 0.0 0.0 3.07 MB

React component and hooks library for Google Maps

Home Page: https://visgl.github.io/react-google-maps/

License: MIT License

Shell 0.60% JavaScript 15.64% TypeScript 81.70% CSS 1.30% MDX 0.76%

react-google-maps's Introduction

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

MIT License

This is a TypeScript / JavaScript library to integrate the Maps JavaScript API into your React application. It comes with a collection of React components to create maps, markers and infowindows, and a set of hooks to use some of the Maps JavaScript API Services and Libraries.

Installation

This library is available on npm as @vis.gl/react-google-maps.

npm install @vis.gl/react-google-maps

or

yarn add @vis.gl/react-google-maps

(PowerShell users: since @ has a special meaning in PowerShell, the package name has to be quoted)

Usage

Import the APIProvider and wrap it around all components that should have access to the Google Maps API. Any component within the context of the APIProvider can use the hooks and components provided by this library.

To render a simple map, add a Map component inside the APIProvider. Within the Map component, you can then add further components like Marker, AdvancedMarker, or InfoWindow to render content on the map.

For more advanced use-cases you can even add your own components to the map that make use of google.maps.OverlayView or google.maps.WebGlOverlayView.

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;

Please see our documentation or examples for more in-depth information about this library.

Using other libraries of the Maps JavaScript API

Besides rendering maps, the Maps JavaScript API has a lot of additional libraries for things like geocoding, routing, the Places API, Street View, and a lot more. These libraries are not loaded by default, which is why this module provides the useMapsLibrary() hook to handle dynamic loading of additional libraries.

For example, if you want to use the google.maps.places.PlacesService class in your component, you can implement it like this:

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 <></>;
};

Examples

Explore our examples directory on GitHub or the examples on our website for full implementation examples.

react-google-maps's People

Contributors

usefulthink avatar dependabot[bot] avatar github-actions[bot] avatar mrmetalwood avatar leighhalliday avatar shuuji3 avatar wangela avatar arielbenichou avatar plumdumpling avatar achhunna avatar amuramoto avatar benschlegel avatar chestermjr avatar jlburkhead avatar wanderingbrooks avatar mauriciorobayo avatar thekip avatar trustdec avatar osmanonurcan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.