Skip to content

Instantly share code, notes, and snippets.

@MicheleBertoli
Created September 5, 2017 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MicheleBertoli/a7c510e9c665e052edfff49bec97a794 to your computer and use it in GitHub Desktop.
Save MicheleBertoli/a7c510e9c665e052edfff49bec97a794 to your computer and use it in GitHub Desktop.
InfoWindow
const coords = {
lat: 51.5258541,
lng: -0.08040660000006028,
};
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
showInfoWindow: false,
};
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
this.setState(prevState => ({
showInfoWindow: !prevState.showInfoWindow,
}));
}
render() {
return (
<div>
<Gmaps
height={300}
lat={coords.lat}
lng={coords.lng}
width={400}
zoom={12}>
<Marker
lat={coords.lat}
lng={coords.lng}
/>
{this.state.showInfoWindow &&
<InfoWindow
lat={coords.lat}
lng={coords.lng}
pixelOffset={new google.maps.Size(0, -40)}
onCloseClick={this.handleClick}
/>
}
</Gmaps>
<button onClick={this.handleClick}>Click me!</button>
</div>
);
}
};
@hermawan22
Copy link

Ah, this is what i looking for. 👍
Very helpful and thanks for your kindness man. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment