Last active
December 4, 2017 15:23
-
-
Save princessjanf/4daab34ff4a9559c2c9207abcf0b632a to your computer and use it in GitHub Desktop.
Method to get google directions api
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
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