Created
September 5, 2017 20:37
-
-
Save MicheleBertoli/a7c510e9c665e052edfff49bec97a794 to your computer and use it in GitHub Desktop.
InfoWindow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, this is what i looking for. 👍
Very helpful and thanks for your kindness man. 👍