Comments (4)
Hi @DeanKamali,
The correct way of adding restrictions to the autocomplete is by adding thm to the getPlacePredictions
call on line 9:
this.placesService.getPlacePredictions(
{
componentRestrictions: {...},
location: {...},
input: value,
},
this.fetchSuggestionsCallback,
);
I haven't tested this myself, but you can take a look here for why I think this is the correct approach:
- https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service
- https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompletionRequest
I'll be able to add that feature next week, but if this seems to work feel free to open a PR! ๐
from react-google-places-autocomplete.
@DeanKamali I have tested this and it works! Working on a new version with the feature now
from react-google-places-autocomplete.
@Tintef thatโs awesome! Iโm also hoping if you could figure out how to get postal code / zip code! Itโs crucial to have this info when processing payments for example.
from react-google-places-autocomplete.
It's not possible to get the postal code from the placesPrediction
call. In order to get that information another API call is necessary using the Geocoder
. Here's a little script on how to obtain the postal code:
const geocoder = new google.maps.Geocoder();
geocoder.geocode({ placeId: <placeId> }, (res, status) => {
if (status === 'OK') {
const postalCode = res[0].address_components.find(component => (
component.types.some(type => type === 'postal_code')
));
if (postalCode) {
/* use the obtained postal code
notice postalCode is an object like the following:
{ long_name: <longName>, short_name: <shortName> }
*/
}
} else {
/* Error */
}
});
You should get the placeId
from the onSelect
function provided to the GooglePlacesAutocomplete
component.
Hope this helps, I'll try to add this option later on, but this should do the trick for the moment.
from react-google-places-autocomplete.
Related Issues (20)
- Form control input value going out of view HOT 3
- City Filtering HOT 4
- Get full country name and country code
- Autocomplete options are behind other sections HOT 3
- Styling HOT 1
- Error: [react-google-places-autocomplete]: Google script not loaded HOT 4
- Error accessing 'place_id' property when rendering component dynamically HOT 1
- Error whle compiling HOT 1
- Placeholder not clearing on focus HOT 1
- Query & Show Suggestions on Focus
- handling of error when request quotas exceeded for 'places api'
- how to style the input HOT 2
- Autocomplete Request: Bounds deprecated HOT 1
- isMulti Prop Does Not Accept true in react-google-places-autocomplete v4.0.1
- Setting pointerEvents on listView Not Honored
- Google Maps JavaScript API has been loaded directly without loading=async HOT 11
- Minimizing Data Requests to Stay Within Google Places API Free Tier
- Getting warning regarding "Google Maps JavaScript API has been loaded directly without loading=async. This can result in suboptimal performance. For best-practice loading patterns please see https://goo.gle/js-api-loading HOT 2
- PlaceHolder not showing HOT 2
- Autofill functionality in browsers fails to operate when the placeholder is anything other than an empty string.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-google-places-autocomplete.