Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fetchRoute = async (ori, dest) => {
- let origin = ori.latitude+','+ori.longitude;
- let destination = encodeURIComponent(dest);
- const key = "MyAPIKey";
- const URL = `https://maps.googleapis.com/maps/api/directions/json?origin=${origin}&destination=${destination}&key=${key}`;
- try{
- const response = await fetch(URL)
- const route = await response.json()
- console.log(route)
- return route
- }catch(e){
- return e
- }
- }
- export default class App extends Component{
- state = {
- userLocation: null,
- route: [],
- }
- getRouteHandler = (text) => {
- fetchRoute(this.state.userLocation, text).then(json => console.log(json));
- }
Add Comment
Please, Sign In to add comment