Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react google places auto complete example

import React from 'react';import PlacesAutocomplete, {  geocodeByAddress,  getLatLng,} from 'react-places-autocomplete'; class LocationSearchInput extends React.Component {  constructor(props) {    super(props);    this.state = { address: '' };  }   handleChange = address => {    this.setState({ address });  };   handleSelect = address => {    geocodeByAddress(address)      .then(results => getLatLng(results[0]))      .then(latLng => console.log('Success', latLng))      .catch(error => console.error('Error', error));  };   render() {    return (      <PlacesAutocomplete        value={this.state.address}        onChange={this.handleChange}        onSelect={this.handleSelect}      >        {({ getInputProps, suggestions, getSuggestionItemProps, loading }) => (          <div>            <input              {...getInputProps({                placeholder: 'Search Places ...',                className: 'location-search-input',              })}            />            <div className="autocomplete-dropdown-container">              {loading && <div>Loading...</div>}              {suggestions.map(suggestion => {                const className = suggestion.active                  ? 'suggestion-item--active'                  : 'suggestion-item';                // inline style for demonstration purpose                const style = suggestion.active                  ? { backgroundColor: '#fafafa', cursor: 'pointer' }                  : { backgroundColor: '#ffffff', cursor: 'pointer' };                return (                  <div                    {...getSuggestionItemProps(suggestion, {                      className,                      style,                    })}                  >                    <span>{suggestion.description}</span>                  </div>                );              })}            </div>          </div>        )}      </PlacesAutocomplete>    );  }}
Comment

PREVIOUS NEXT
Code Example
Javascript :: find option values using javascript 
Javascript :: JSX element event listeners 
Javascript :: angular property binding 
Javascript :: Remove Array Duplicate 
Javascript :: deparam javascript 
Javascript :: puppeteer example multiple file upload 
Javascript :: console.table in js without index column 
Javascript :: how to get value of tinymce in javascript 
Javascript :: import slider material ui 
Javascript :: arrow functions javascript 
Javascript :: es6 range 
Javascript :: how to disable menu bar in browser using javascript 
Javascript :: javascript set value to the largest value in an array 
Javascript :: next js generate pdf complete 
Javascript :: animated node with tag 1 does not exist 
Javascript :: Laravel react 404 routes 
Javascript :: appendchild element once if element present in js 
Javascript :: vue route automatic redirect 
Javascript :: how to make array empty 
Javascript :: jquery get data element 
Javascript :: print js example 
Javascript :: add to array applescript 
Javascript :: Detect Pangram 
Javascript :: react set initial state without constructor 
Javascript :: setstate 
Javascript :: global scope js 
Javascript :: mongoos populate a ref 
Javascript :: get query params from url 
Javascript :: javascript sleep one second 
Javascript :: search node in tree javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =