Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

google map in react js

import React, { Component } from 'react';
import GoogleMapReact from 'google-map-react';

const AnyReactComponent = ({ text }) => <div>{text}</div>;

class SimpleMap extends Component {
  static defaultProps = {
    center: {
      lat: 59.95,
      lng: 30.33
    },
    zoom: 11
  };

  render() {
    return (
      // Important! Always set the container height explicitly
      <div style={{ height: '100vh', width: '100%' }}>
        <GoogleMapReact
          bootstrapURLKeys={{ key: /* YOUR KEY HERE */ }}
          defaultCenter={this.props.center}
          defaultZoom={this.props.zoom}
        >
          <AnyReactComponent
            lat={59.955413}
            lng={30.337844}
            text="My Marker"
          />
        </GoogleMapReact>
      </div>
    );
  }
}

export default SimpleMap;
Comment

react google map

npm install --save google-map-react
Comment

google map react search place

npm install google-map-react
Comment

react google map api

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

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

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

function MyComponent() {
  const { isLoaded } = useJsApiLoader({
    id: 'google-map-script',
    googleMapsApiKey: "YOUR_API_KEY"
  })

  const [map, setMap] = React.useState(null)

  const onLoad = React.useCallback(function callback(map) {
    // This is just an example of getting and using the map instance!!! don't just blindly copy!
    const bounds = new window.google.maps.LatLngBounds(center);
    map.fitBounds(bounds);

    setMap(map)
  }, [])

  const onUnmount = React.useCallback(function callback(map) {
    setMap(null)
  }, [])

  return isLoaded ? (
      <GoogleMap
        mapContainerStyle={containerStyle}
        center={center}
        zoom={10}
        onLoad={onLoad}
        onUnmount={onUnmount}
      >
        { /* Child components, such as markers, info windows, etc. */ }
        <></>
      </GoogleMap>
  ) : <></>
}

export default React.memo(MyComponent)
Comment

how to add google map in react js

import React, { Component } from 'react';import GoogleMapReact from 'google-map-react'; const AnyReactComponent = ({ text }) => <div>{text}</div>; class SimpleMap extends Component {  static defaultProps = {    center: {      lat: 59.95,      lng: 30.33    },    zoom: 11  };   render() {    return (      // Important! Always set the container height explicitly      <div style={{ height: '100vh', width: '100%' }}>        <GoogleMapReact          bootstrapURLKeys={{ key: /* YOUR KEY HERE */ }}          defaultCenter={this.props.center}          defaultZoom={this.props.zoom}        >          <AnyReactComponent            lat={59.955413}            lng={30.337844}            text="My Marker"          />        </GoogleMapReact>      </div>    );  }} export default SimpleMap;
Comment

PREVIOUS NEXT
Code Example
Javascript :: getting average of array javascript 
Javascript :: set a value in session using javascript 
Javascript :: js to lowercase 
Javascript :: filereader check file type 
Javascript :: reset input react 
Javascript :: react js marked import and use 
Javascript :: javascript take last element of array 
Javascript :: json data sample 
Javascript :: onclick function jquery 
Javascript :: mongoose reset database 
Javascript :: viewmodelprovider example 
Javascript :: http to https redirect express js 
Javascript :: filter out undefined from object javascript 
Javascript :: why is my mongoose middleware not working 
Javascript :: javascript replace last occurrence of a letter 
Javascript :: First non repeating character position in a string 
Javascript :: javascript round to 8 decimal places 
Javascript :: express receive post 
Javascript :: setinterval stop onditional stop 
Javascript :: genius lyrics api 
Javascript :: app.use bodyparser 
Javascript :: convert mongodb timestamp to date javascript 
Javascript :: javascript response redirect 
Javascript :: javascript arithmetic operators 
Javascript :: jquery if class clicked 
Javascript :: uploading file with fetch 
Javascript :: tinymce event on change 
Javascript :: multiply function javascript 
Javascript :: jqery get text 
Javascript :: if cart empty shopify 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =