React-google-maps: How to make SearchBox Outside on Google Maps

Created on 12 Jun 2017  路  2Comments  路  Source: tomchentw/react-google-maps

I want to custom searchbox autocomplete on Google Maps. How to make searchbox outside on google maps?

Most helpful comment

You can put an input anywhere by doing like this :

<input
    ref={(c) => {
      if (!c) {
        return;
      }
      const searchBox = new google.maps.places.SearchBox(c, { types: ['geocode'] });
      searchBox.addListener('places_changed', ()=> {
        const places = searchBox.getPlaces();
        if (places.length > 0) {
          const position = places[0].geometry.location;
          ...
        }
      })
    }}
    placeholder="Search a place..."
    type="text"
    style={styles.input}
  />

All 2 comments

Google doesn't support this.

Please refer to Getting Help section in the README.

You can put an input anywhere by doing like this :

<input
    ref={(c) => {
      if (!c) {
        return;
      }
      const searchBox = new google.maps.places.SearchBox(c, { types: ['geocode'] });
      searchBox.addListener('places_changed', ()=> {
        const places = searchBox.getPlaces();
        if (places.length > 0) {
          const position = places[0].geometry.location;
          ...
        }
      })
    }}
    placeholder="Search a place..."
    type="text"
    style={styles.input}
  />
Was this page helpful?
0 / 5 - 0 ratings