Google-maps-react: Getting distance and directions between two places

Created on 18 Feb 2018  路  2Comments  路  Source: fullstackreact/google-maps-react

Hi All, Can anyone help with getting the distance and directions between two points. I have manged to put the code like this

getDirections=(e)=>
{
const {google} = this.props;
const directionsService = new google.maps.DirectionsService();
const directionsDisplay = new google.maps.DirectionsRenderer();
var request = {
origin: this.state.origin,
destination: this.state.destination,
travelMode: 'DRIVING'
};
directionsService.route(request, function(result, status) {
console.log(result)
if (status === 'OK') {
directionsDisplay.setDirections(result);
}
else
{
window.alert('Directions request failed due to ' + status);
}
});
}

But this is not showing anything on the map, please help.

All 2 comments

Can you put together a gist? I can try to help debug with more context...

Hi Guys,
sorry to re-open an old conversation but does anyone have something for directions that works?
Thanks

Was this page helpful?
0 / 5 - 0 ratings