Guest User

Untitled

a guest
Dec 15th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import React from 'react';
  2. import GoogleMap from 'google-distance-matrix';
  3. class SimpleForm extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. address: '',
  8. dest:'',
  9. distanceText:'testing the distance text'
  10. }
  11. this.handleFormSubmit = this.handleFormSubmit.bind(this);
  12.  
  13. this.onChange = (address) => this.setState({ address });
  14. this.changeDest = (dest) => this.setState({dest});
  15. }
  16. handleFormSubmit = (event) => {
  17. event.preventDefault()
  18. GoogleMap.matrix(this.state.address, this.state.dest, function (err, distances) {
  19. if (err) {
  20. return console.log(err);
  21. }
  22. if(!distances) {
  23. return console.log('no distances');
  24. }
  25. if (distances.status == 'OK') {
  26. if(distances.rows[0].elements[0]) {
  27. var distance = distances.rows[0].elements[0].duration['text'];
  28. this.setState({
  29. foundDistance: true,
  30. distanceText: distance
  31.  
  32. });
  33. }
  34. }
  35. });
  36.  
  37. }
Add Comment
Please, Sign In to add comment