ErrorPro / react-google-autocomplete

React components for google places API.
MIT License
473 stars 114 forks source link

will only return city not full address #149

Closed russmenum closed 2 years ago

russmenum commented 2 years ago

Am trying to get a full address, but this library seems to only work for the city, not the full address?

<Autocomplete
            className="location"

            apiKey={process.env.REACT_APP_GOOGLE_MAPS_API}
            onPlaceSelected={(place) => {
              console.log(place);
            }}
            componentRestrictions={{ country: "us" }}
            options={{
              types: ["address"],
              fields: ["formatted_address"]
            }}
          />
BrianBaePicobyte commented 2 years ago

Are you sorted this? If you change the options.types to geocode, you can get a full address.

options: { componentRestrictions: { country: "us" }, types: ["geocode"], },

ErrorPro commented 2 years ago

Feel free to reopen it if that still doesn't work for you

russmenum commented 2 years ago

It seems the core problem is onload it is not setting the API key?

Google maps places API must be loaded.
<Autocomplete
            className="location"

            // apiKey={process.env.REACT_APP_GOOGLE_MAPS_API}
            apiKey={googleKeyState}
            onPlaceSelected={(place) => {
              //console.log(place);
              handleLocation(place);
            }}
            options={{
              componentRestrictions: { country: "us" },
              types: ["geocode"],
            }}
          />

Does not matter if I pass it from env, or state, or directly there as a string. It won't load it until I refresh the screen at least one time.

Is there some load for the apiKey I am missing so it will load first time and be ready

russmenum commented 2 years ago

Feel free to reopen it if that still doesn't work for you

I do not think I can when you close it for me?