react googlemap code example

Example 1: react google maps api

import React from 'react'
import { GoogleMap, LoadScript } from '@react-google-maps/api';

const containerStyle = {
  width: '400px',
  height: '400px'
};

const center = {
  lat: -3.745,
  lng: -38.523
};

function MyComponent() {
  return (
    <LoadScript
      googleMapsApiKey="YOUR_API_KEY"
    >
      <GoogleMap
        mapContainerStyle={containerStyle}
        center={center}
        zoom={10}
      >
        { /* Child components, such as markers, info windows, etc. */ }
        <></>
      </GoogleMap>
    </LoadScript>
  )
}

export default React.memo(MyComponent)

Example 2: google maps react

/* Answer to: "google maps react"  */

/*
  "google-map-react" is a component written over a small set of the
  Google Maps API. It allows you to render any React component on
  the Google Map. It is fully isomorphic and can render on a server
  Additionally, it can render map components in the browser even if
  the Google Maps API is not loaded. It uses an internal, tweakable
  hover algorithm - every object on the map can be hovered.
  
  Install it here:
  https://www.npmjs.com/package/google-maps-react
  
  Don't forget it's also open-source! Here's the github page:
  https://github.com/google-map-react/google-map-react
*/