xxxxxxxxxx
const mode = 'driving'; // 'walking';
const origin = 'coords or address';
const destination = 'coords or address';
const APIKEY = 'XXXXXXXXXXXX';
const url = `https://maps.googleapis.com/maps/api/directions/json?origin=${origin}&destination=${destination}&key=${APIKEY}&mode=${mode}`;
fetch(url)
.then(response => response.json())
.then(responseJson => {
if (responseJson.routes.length) {
this.setState({
coords: this.decode(responseJson.routes[0].overview_polyline.points) // definition below
});
}
}).catch(e => {console.warn(e)});