Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import GoogleMap from 'google-distance-matrix';
- class SimpleForm extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- address: '',
- dest:'',
- distanceText:'testing the distance text'
- }
- this.handleFormSubmit = this.handleFormSubmit.bind(this);
- this.onChange = (address) => this.setState({ address });
- this.changeDest = (dest) => this.setState({dest});
- }
- handleFormSubmit = (event) => {
- event.preventDefault()
- GoogleMap.matrix(this.state.address, this.state.dest, function (err, distances) {
- if (err) {
- return console.log(err);
- }
- if(!distances) {
- return console.log('no distances');
- }
- if (distances.status == 'OK') {
- if(distances.rows[0].elements[0]) {
- var distance = distances.rows[0].elements[0].duration['text'];
- this.setState({
- foundDistance: true,
- distanceText: distance
- });
- }
- }
- });
- }
Add Comment
Please, Sign In to add comment