I'm creating an ecommerce app and we need the postal code to calculate shipping costs, using address autocomplete from google place api, not sure if it's a limitation from the api, but it doesn't return a postal code. I'm using https://github.com/FaridSafi/react-native-google-places-autocomplete for the autocomplete.
I looked through google docs as well, and it doesn't mention anything about it.
Just wondering if there's a way to get a postal code from an address?
The Google autocomplete API does not return a postal code as part of its results.
The package you mentioned has a fetchDetails
props, which will call the Google Places API to get more information including the postal code. You can then access the data from details
in onPress
.
import React from 'react';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
const GooglePlacesInput = () => {
return (
<GooglePlacesAutocomplete
placeholder='Search'
fetchDetails={true}
onPress={(data, details) => {
console.log('data: ', data);
console.log('details: ', details);
}}
query={{
key: 'YOUR API KEY',
language: 'en',
}}
/>
);
};
export default GooglePlacesInput;