Google-maps-react: onDragend and getting the new LatLng of the center of the map

Created on 11 Jul 2019  Â·  5Comments  Â·  Source: fullstackreact/google-maps-react

I've a basic map...

<Map
        google={google}
        zoom={13}
        style={mapStyles}
        initialCenter={userCoordinates}
        onClick={this.onMapClick}
        styles={style}
        onDragend={this.centerMoved}
      />

thing to note is the onDragend property... I have it mapped to fire this.centerMoved... which is defined as such. I can't seem to figure out how to get the new map's Lat and Lng at this point...

centerMoved = (mapProps, map) => {
    console.log(mapProps.google.maps.LatLng()); // returns undefined
};

Is there any way to get this information? Am I using the wrong event?

Most helpful comment

centerMoved(mapProps, map) {
        console.log('args:', mapProps, map);
        console.log(map.getCenter().lat());
}

All 5 comments

@matgargano did you ever figure this out? Running into the same thing

I Don’t believe so.

On Nov 3, 2019, at 10:18 PM, James Livengood notifications@github.com wrote:


@matgargano did you ever figure this out? Running into the same thing

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

any solution for this ?

i found the solution :
https://stackoverflow.com/a/51496164

@matgargano your center moved function should be like this:

centerMoved = (mapProps, map) => {
    console.log('center: '+map.getCenter());
    console.log('center: '+map.center);
};
centerMoved(mapProps, map) {
        console.log('args:', mapProps, map);
        console.log(map.getCenter().lat());
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

t1a2l picture t1a2l  Â·  5Comments

kkinaman picture kkinaman  Â·  3Comments

cernoel picture cernoel  Â·  3Comments

joeyfigaro picture joeyfigaro  Â·  3Comments

mruoss picture mruoss  Â·  5Comments