Created
July 18, 2018 06:38
-
-
Save jamesattard/a9a9437fabccf4b0f49737601a2e3c5d to your computer and use it in GitHub Desktop.
Asynchronous setState()
This file contains hidden or 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
setCoords = coords => { | |
this.setState({ | |
lat: coords.lat, | |
lng: coords.lng | |
}); | |
}; | |
componentDidMount() { | |
let geocoder = new window.google.maps.Geocoder(); | |
geocoder.geocode( | |
{ address: this.props.address }, | |
async (results, status) => { | |
if (status === "OK") { | |
const coords = await results[0].geometry.location.toJSON(); | |
await this.setCoords(coords); | |
} else { | |
console.log( | |
"Geocode was not successful for the following reason: " + status | |
); | |
} | |
} | |
); | |
this.delayedShowMarker(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment