cedricdelpoux / react-google-places-suggest

React component to select geolocated suggestion from Google Maps Places API
https://cedricdelpoux.github.io/react-google-places-suggest/
MIT License
86 stars 44 forks source link

send country as parameter in request #52

Closed usmanghani720 closed 5 years ago

usmanghani720 commented 5 years ago
const suggestComponentRestrictions = {
  country: ["us"],
}

<ReactGoogleMapLoader
  params={{
    key: MY_API_KEY,
    libraries: "places,geocode",
  }}
  render={googleMaps =>
    googleMaps && (
      <ReactGooglePlacesSuggest
        googleMaps={googleMaps}
        autocompletionRequest={{
          input: search,
        }}
        suggestComponentRestrictions={suggestComponentRestrictions}
        onNoResult={this.handleNoResult}
        onSelectSuggest={this.handleSelectSuggest}
        onStatusUpdate={this.handleStatusUpdate}
        textNoResults="No results found"
        customRender={prediction => (
          <div className="customWrapper">
            {prediction ? prediction.description : "No results found"}
          </div>
        )}
      >
        <Input
          autoComplete="none"
          type="text"
          value={value}
          placeholder="Search a high school"
          onChange={this.handleInputChange}
          onFocus={this.handlefocusOut.bind(this)}
        />
      </ReactGooglePlacesSuggest>
    )
  }
/>

This is my piece of code, I want to fetch results from US only but I am not getting the filtered results, can anybody help me with this

cedricdelpoux commented 5 years ago

Please try this instead:

<ReactGooglePlacesSuggest
    googleMaps={googleMaps}
    autocompletionRequest={{
        input: search,
        componentRestrictions: {
        country: ["us"],
        }
    }}
/>
usmanghani720 commented 5 years ago

Hey thanks a million @xuopled , this seems to work..honestly you are a lifesaver..

cedricdelpoux commented 5 years ago

You are welcome 🙂Happy to help