Some options not accepted
The docs say.
options: Google autocomplete options.
options.types: By default it uses (cities). options.fields: By default it uses address_components, geometry.location, place_id, formatted_address. defaultValue prop is used for setting up the default value e.g defaultValue={'Amsterdam'}.
But those don't seem to work.
const Address: React.FC<Props> = ({ apiKey }) => {
const [mapLoaded, setMapLoaded] = useState(false);
const { ref, autocompleteRef } = usePlacesWidget({
apiKey: "MY_API_KEY,
libraries: ["places"],
options: {
types: ["address"],
fields: ["address_components", "geometry", "icon", "name"],
},
defaultValue: {'Amsterdam'},
onPlaceSelected: (place) => {
console.log(place);
},
});
Fails to build at all with:
TS2345: Argument of type '{ apiKey: string; libraries: string[]; options: { types: string[]; fields: string[]; }; defaultValue: { Amsterdam: any; }; onPlaceSelected: (place: PlaceResult) => void; }' is not assignable to parameter of type 'ReactGoogleAutocompleteProps'.
Object literal may only specify known properties, and 'defaultValue' does not exist in type 'ReactGoogleAutocompleteProps'.
17 | fields: ["address_components", "geometry", "icon", "name"],
18 | },
> 19 | defaultValue: {'Amsterdam'},
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
20 | onPlaceSelected: (place) => {
21 | console.log(place);
22 | },
Furthermore, with the default settings, I only get results from India and Pakistan.
Ok, after 3-4 iterations, (and removing the failed defaultValue field it suddenly started returning more rational answers, but ... and this is a big but, I cannot convince it to give me an address which includes the zip code.
It always returns results of the form 234 Crooked Creek Parkway, Durham, NC, USA which, ok, that's reasonable, but I'd ideally like to be able to get at the place.address_component so I can fill in the other fields in the form?
Any help?