Reputation: 343
Since I am new to React Js, I wanted to use google address autocomplete service. So i came to find npm package "react-places-autocomplete" package which is great to implement. But one this i came to found that it return address but no postal_code. Since i needed post_code, has anybody ever done customization to get postal_code using this package ?
id: "0a69230df738495807b4d2a21e399895416cf7ae", description: "8 Burnley Street, Richmond VIC,
Australia", placeId: "ChIJ-RqIcFND1moR6pgdVLp_7Ss", active: false, index: 4, …}
id: "0a69230df738495807b4d2a21e399895416cf7ae"
description: "8 Burnley Street, Richmond VIC, Australia"
placeId: "ChIJ-RqIcFND1moR6pgdVLp_7Ss"
active: false
index: 4
formattedSuggestion: {mainText: "8 Burnley Street", secondaryText: "Richmond VIC, Australia"}
matchedSubstrings: (2) [{…}, {…}]
terms: (5) [{…}, {…}, {…}, {…}, {…}]
types: (2) ["street_address", "geocode"]
__proto__: Object
Postal Code is missing in the response. I hope to get atleast some hints how to do it.
Upvotes: 4
Views: 3812
Reputation: 2404
react-places-autocomplete will probably only be using the Places Autocomplete Service, in which case I don't believe that it returns a postcode at all.
So the simple answer would be no, you can't directly get the postcode from react-places-autocomplete or the google places autocomplete service.
The long answer would be, you can make use of other google and free services to get the postcode.
In your prediction you will have a property called place_id
, you can then use that with googles getDetails, for example, to get a PlaceResult where you can then get address details.
If at this point you still can't get what you need from google you can then use a free service like https://postcodes.io/ to get the postcode from the lat and lng coordinates.
I have a blog post about using react with google places autocomplete service here that you might find useful.
And a post here about how you can use postcodes with the JavaScript Google Places Api
Sources:
Upvotes: 1