react google maps get map center

Solutions on MaxInterview for react google maps get map center by the best coders in the world

showing results for - "react google maps get map center"
Sakina
20 Apr 2017
1import React, { useState } from 'react';
2import { GoogleMap, LoadScript } from '@react-google-maps/api';
3import mapStyle from './mapStyle';
4const mapContainerStyle = {
5  height: "300px",
6  width: "100%"
7};
8const FormMap = () => {
9  const [mapRef, setMapRef] = useState(null);
10  const [center, setCenter] = useState({ lat: 48.1467112, lng: 17.1385319 });
11  const [clickedLatLng, setClickedLatLng] = useState(null);
12  return (
13    <>
14      <LoadScript
15        id="form-map"
16        googleMapsApiKey={process.env.REACT_APP_GOOGLE_MAPS_API_KEY}
17        version="weekly"
18      >
19        <GoogleMap
20          id="form-map"
21          // Store a reference to the google map instance in state
22          onLoad={map => setMapRef(map)}
23          onClick={e => setClickedLatLng(e.latLng.toJSON())}
24          zoom={14}
25          center={center}
26          onCenterChanged={() => setCenter(mapRef.getCenter().toJSON())}
27          mapContainerStyle={mapContainerStyle}
28          clickableIcons
29          options={{
30            disableDefaultUI: true,
31            styles: mapStyle,
32          }}
33        >
34        </GoogleMap>
35      </LoadScript>
36      {/* Our center position always in state */}
37      <h3>
38        Center {center.lat}, {center.lng}
39      </h3>
40      {/* Position of the user's map click */}
41      {clickedLatLng && (
42        <h3>
43          You clicked: {clickedLatLng.lat}, {clickedLatLng.lng}
44        </h3>
45      )}
46    </>
47  )
48}
49export default FormMap;
queries leading to this page
react google map change centremap style center react google mapsget center of map react google maps boundinggoogle map react set centerreact google maps change centerreact maps center soutegoogle maps loses map center reactreact google maps do i have to give center to the maogoogle map component set centerreact google maps get map center how to react google maps center map stylegoogle maps react api change centerreact google maps centerreact google map centerreact google maps get center on clickgoogle map react get centerreact google maps auto centerreact google map how to center on your location at loadreact google maps api centercenter react map glreact google maps api change centercenter changed google maps reactgoogle maps center map reactreact google maps center to nulreact google maps component on change center functionreact google maps how do you set centergoogle map react default centerget center of react google mapgoogle map react centergoogle maps react centergoogle maps react center at my locationhow to get the google map current center position react google mapsset center of map google maps reactget center of map react google mapsgoogle map react change centergoogle map react centerhow to get the google map current center position reactgoogle map react change centerreact google map off centerget center react map gl 40react google maps 2fapi default map position centergoogle map react update centerget center of map react bounding google maps reactset center of map google maps reactreact google map api put map in centerreact google maps make center of the map coordinatesgoogle map react initial centerreact google maps get map center