Problem Description
I’m having an issue with the new Google Autocomplete API not returning street addresses as in earlier versions:
- Previous Behavior: The API accepted a type: [“address”] parameter
which returned only full addresses - Current Behavior: When I type “V”,
I get countries like “Vietnam” instead of street addresses starting
with “V” - Desired Outcome: I want to list only full street addresses
to users
What I’ve Tried
Looking at Google’s documentation, there’s a property called includedPrimaryTypes which accepts values like “street_address” or “street_number”, but this doesn’t seem to be working correctly it returns only specific street addresses not all that Google offers.
My Current Code
const { AutocompleteSuggestion } = await google.maps.importLibrary("places");
const { suggestions: fetchedSuggestions } = await AutocompleteSuggestion.fetchAutocompleteSuggestions({
input,
sessionToken: token.value,
// includedPrimaryTypes: ["street_address", "street_number", "premise"],
});
suggestions.value = await Promise.all(
fetchedSuggestions.map(
async (suggestion: google.maps.places.AutocompleteSuggestion) => {
const place = suggestion.placePrediction.toPlace();
await place.fetchFields({
fields: ["formattedAddress"],
});
return {
placePrediction: suggestion.placePrediction,
formattedAddress: place.formattedAddress,
};
},
),
);
- How can I filter results to only include street addresses?
- Is there a replacement for the previous type: [“address”] parameter?
- What’s the correct way to use includedPrimaryTypes if that’s the right approach?