google-maps-react
google-maps-react copied to clipboard
onDragend and getting the new LatLng of the center of the map
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?
@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 [email protected] 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());
}
I've had the exact same problem but I managed to get the new center values by using the following (it only showed up using the "toJSON"
onBoundsChange(mapProps, map) {
this.setState({
center: map.getCenter().toJSON()
});
}
centerMoved(mapProps, map) { console.log('args:', mapProps, map); console.log(map.getCenter().lat()); }
this return undefined value sir. How can I do it?