react-places-autocomplete icon indicating copy to clipboard operation
react-places-autocomplete copied to clipboard

Fetch Zip Code

Open Hamzajoshan opened this issue 5 years ago • 1 comments
trafficstars

Is there any way to fetch the zipcode of the current address? kindly let me know ASAP thank u.

Hamzajoshan avatar Jul 30 '20 17:07 Hamzajoshan

You can use the geoCodeByPlaceId helper to grab the full location on select.

const onSuggestionSelect = async (address, placeId, suggestion) => {

const [place] = await geocodeByPlaceId(placeId);
const {long_name:postalCode = ''} = place.address_components.find( c => c.types.includes('postal_code')) || {};

console.log(postalCode);

jchamb avatar Oct 02 '20 14:10 jchamb