Skip to content

Instantly share code, notes, and snippets.

@princessjanf
Last active December 4, 2017 15:23
Show Gist options
  • Save princessjanf/4daab34ff4a9559c2c9207abcf0b632a to your computer and use it in GitHub Desktop.
Save princessjanf/4daab34ff4a9559c2c9207abcf0b632a to your computer and use it in GitHub Desktop.
Method to get google directions api
async getDirections(startLoc, destinationLoc) {
try {
let resp = await fetch(`https://maps.googleapis.com/maps/api/directions/json?origin=${ startLoc }&destination=${ destinationLoc }`)
let respJson = await resp.json();
let points = Polyline.decode(respJson.routes[0].overview_polyline.points);
let coords = points.map((point, index) => {
return {
latitude : point[0],
longitude : point[1]
}
})
this.setState({coords: coords})
return coords
} catch(error) {
alert(error)
return error
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment