Hi, Thanks for support this library.
I have a question regarding get data to parse zipcode and country.
Are there any ref or doc to get/parse zipcode, country strings?
Thanks.
I have the same question, but I need to get Country, State, City and zip code. Can I do that?
I need this also
yes i also need to get just state
I need this to
Check out the available options in Place autocomplete
geocodeinstructs the Place Autocomplete service to return only geocoding results, rather than business results. Generally, you use this request to disambiguate results where the location specified may be indeterminate.
address instructs the Place Autocomplete service to return only geocoding results with a precise address. Generally, you use this request when you know the user will be looking for a fully specified address.
establishment instructs the Place Autocomplete service to return only business results.
the (regions) type collection instructs the Places service to return any result matching the following types:
locality
sublocality
postal_code
country
administrative_area_level_1
the (cities) type collection instructs the Places service to return results that match locality or administrative_area_level_3.
I don't know if this will help someone, but I needed to show Cities, Country, ZIP CODE on search box.
Then I changed types: 'address' to types: 'geocode' in query:
query={{
key: defaultConst.googlePlacesApiKey,
language: 'pt_BR', // language of the results
types: 'geocode' // default: 'geocode'
}}
Now the search results coming as Country, ZIPCODE, City, State...
Hi there, I also need to include the zip code in the address on both places, in the list, and in the textinput when one item is selected. I do get the complete addres, including zip code from details.formatted_address on onPress. But the row parameter in renderDescription does not include formatted_address, and row.description does not show zip code. Is it possible to tell renderDescription to show formatted_address? Thanks!
how to get the zip code ? Any update ?
Here is solution.
Don't forget to add fetchDetails prop on your <GooglePlacesAutocomplete/> component. Then in onPress will be provided details where you can find address_components and postal_code will be here.
Address components:
[
{
"long_name": "4511",
"short_name": "4511",
"types": [
"street_number"
]
},
{
"long_name": "GlencoeAvenue",
"short_name": "GlencoeAve",
"types": [
"route"
]
},
{
"long_name": "MarinadelRey",
"short_name": "MarinaDelRey",
"types": [
"locality",
"political"
]
},
{
"long_name": "LosAngelesCounty",
"short_name": "LosAngelesCounty",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "California",
"short_name": "CA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "UnitedStates",
"short_name": "US",
"types": [
"country",
"political"
]
},
{
"long_name": "90292",
"short_name": "90292",
"types": [
"postal_code"
]
My example:
<GooglePlacesAutocomplete fetchDetails onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
const { address_components } = details;
if (address_components.length === 0) {
return;
}
getFieldsForAutocomplete(address_components);
...
}}
...
To solve this problem, I used the following solution:
when we enter the street without the number, the postal code is in the details.address_components[5], with that I made a simple check, if the last position exists.
onPress={(data, details) => {
if(details.address_components[6]){
setZip(details.address_components[6])
}else {
setZip(details.address_components[5])
}
...
_remembering that for this to work correctly the type must be address_
Postal-Code Log exemples with i recived:
[5]: {
"long_name": "50750-630", // zip code in my country
"short_name": "50750-630",
"types": Array [
"postal_code",
],
}
[6]: {
"long_name": "50750-630", // zip code in my country
"short_name": "50750-630",
"types": Array [
"postal_code",
],
}
@bell-steven you are closing the issue without providing any solution
It's really hard to track issues and solutions
you are closing the issue without providing any solution
I beg to differ. There are multiple solutions posted here.
It's really hard to track issues and solutions
Not really sure what you mean here.
Since the details address_components array can be different lengths depending on the address input, this is a more reliable way to get zip code
<GooglePlacesAutocomplete
fetchDetails={true}
onPress={(data, details) => {
const zipCode = details?.address_components.find((addressComponent) =>
addressComponent.types.includes('postal_code'),
)?.short_name;
}}
query={{
key: 'YOUR_GOOGLE_KEY_HERE',
language: 'en',
types: 'address',
}}
/>;
Since the details address_components array can be different lengths depending on the address input, this is a more reliable way to get zip code
<GooglePlacesAutocomplete fetchDetails={true} onPress={(data, details) => { const zipCode = details?.address_components.find((addressComponent) => addressComponent.types.includes('postal_code'), )?.short_name; }} query={{ key: 'YOUR_GOOGLE_KEY_HERE', language: 'en', types: 'address', }} />;
This works! Thank you!
Most helpful comment
I have the same question, but I need to get Country, State, City and zip code. Can I do that?