Guest User

Untitled

a guest
Jun 17th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. const fetchRoute = async (ori, dest) => {
  2. let origin = ori.latitude+','+ori.longitude;
  3. let destination = encodeURIComponent(dest);
  4. const key = "MyAPIKey";
  5. const URL = `https://maps.googleapis.com/maps/api/directions/json?origin=${origin}&destination=${destination}&key=${key}`;
  6.  
  7. try{
  8. const response = await fetch(URL)
  9. const route = await response.json()
  10. console.log(route)
  11. return route
  12. }catch(e){
  13. return e
  14. }
  15. }
  16.  
  17. export default class App extends Component{
  18.  
  19. state = {
  20. userLocation: null,
  21. route: [],
  22. }
  23.  
  24. getRouteHandler = (text) => {
  25. fetchRoute(this.state.userLocation, text).then(json => console.log(json));
  26. }
Add Comment
Please, Sign In to add comment