-1

I am making a web app based on reactjs that uses google maps. For using google maps I have used react-google-maps library. I need latitude and longitude of center of map dynamically as it's value can change when map is dragged.

In documentation, it's stated that getCenter() function returns latLng of center of map but I can't find any good example how to use it. So please help me to find the center of map.

Ry-
  • 218,210
  • 55
  • 464
  • 476
Bhuwan Adhikari
  • 879
  • 1
  • 9
  • 21
  • you need to use the `getCenter` method. Use a `ref` for your map component and call `getCenter` method on the `ref`. – Fawaz Jun 20 '19 at 13:15

1 Answers1

0
var mapRef;

var center = mapRef.getCenter();

and in render method

<GoogleMap
       ref={(m) => mapRef = m}
       defaultZoom={3}
       defaultCenter={new google.maps.LatLng(
            {lat:45.1983838, lng:12.0970988})}
       center={props.center}
       zoom={props.zoom}
            >
</GoogleMap>
batt
  • 3,382
  • 2
  • 11
  • 12