Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class About extends Component {
  2.   constructor(props) {
  3.     super(props);
  4.     this.state = {
  5.       address: '',
  6.       directions: null,
  7.       markers: false,
  8.       currentPosLat: 41.8507300,
  9.       currentPosLng: -87.6512600
  10.     };
  11.   }
  12.  
  13.   handleChange = (address) => {
  14.     this.setState({ address });
  15.   };
  16.  
  17.   handleSelect = (address) => {
  18.     geocodeByAddress(address)
  19.       .then(results => getLatLng(results[0]))
  20.       .then(latLng => {
  21.         console.log(this.state.address);
  22.         this.setState({
  23.           currentPosLng: latLng.lng,
  24.           currentPosLat: latLng.lat,
  25.           markers: true
  26.         });
  27.         console.log('Success', latLng);
  28.       })
  29.       .catch(error => console.error('Error', error));
  30.   };
  31.  
  32.   render() {
  33.     return (
  34.       <div>
  35.         <MyGoogleMap
  36.           isMarkerShown
  37.           googleMapURL="https://maps.googleapis.com/maps/api/js?key=AIzaSyB7mvCqVEORmN9sP9xLPKsmag1yqbltU3E&v=3.exp&libraries=geometry,drawing,places"
  38.           loadingElement={<div style={{ height: '100%' }} />}
  39.           containerElement={<div style={{ height: '600px' }} />}
  40.           mapElement={<div style={{ height: '100%' }} />}
  41.           directions={this.state.directions}
  42.           markers={this.state.markers}
  43.           currentPosLat={this.state.currentPosLat}
  44.           currentPosLng={this.state.currentPosLng}
  45.         />
  46.         <PlacesAutocomplete
  47.           value={this.state.address}
  48.           onChange={this.handleChange}
  49.           onSelect={this.handleSelect}
  50.         >
  51.           {({ getInputProps, suggestions, getSuggestionItemProps }) => (
  52.             <div>
  53.               <input
  54.                 {...getInputProps({
  55.                   placeholder: 'Search Places ...',
  56.                   className: 'location-search-input'
  57.                 })}
  58.               />
  59.               <div className="autocomplete-dropdown-container">
  60.                 {suggestions.map(suggestion => {
  61.                   const className = suggestion.active ? 'suggestion-item--active' : 'suggestion-item';
  62.                   // inline style for demonstration purpose
  63.                   const style = suggestion.active
  64.                     ? { backgroundColor: '#fafafa', cursor: 'pointer' }
  65.                     : { backgroundColor: '#ffffff', cursor: 'pointer' };
  66.                   return (
  67.                     <div {...getSuggestionItemProps(suggestion, { className, style })}>
  68.                       <span>{suggestion.description}</span>
  69.                     </div>
  70.                   );
  71.                 })}
  72.               </div>
  73.             </div>
  74.           )}
  75.         </PlacesAutocomplete>
  76.       </div>
  77.     );
  78.   }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement