-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
difficulty with requestOptions #904
Comments
Same problem. |
@Minte-grace Seems you lack the usePlacesAutocomplete({
requestOptions: {
types: "address",
radius: 500,
location: {
lat: 8.7,
+ lng: 38.8,
},
},
debounce: 300,
}); |
@wellyshen |
what is not working? |
I'm also running into issues when trying to provide a the const {
ready,
value,
suggestions: { status, data },
setValue
} = usePlacesAutocomplete({
requestOptions: {
location: { lat: 40.7127753, lng: -74.0059728 } // Having this causes autocomplete to not work
}
}); Oddly not seeing anything out of the ordinary in the console and logging |
Try also specifying a |
Ah yeah, I did try that as well but no luck. |
I had the same issue, but adding Also, I've upgraded to v2.0.0, not sure if it makes a difference. And also, you may want to clear the site data after doing so. (P.S: Make sure to clear the site data for localhost:3000 only. I once cleared site data for all websites by mistake or something, logging me out of all my accounts) |
Thanks @hossameldeen. Unfortunately, that also didn't work for me. I was only able to get it to work by passing an instance of const {
ready,
value,
suggestions: { status, data },
setValue
} = usePlacesAutocomplete({
requestOptions: {
location: new window.google.maps.LatLng(40.7127753, -74.0059728),
radius: 5000,
}
}); |
When debugging the issue, I've found that Here, we set
If use-places-autocomplete/src/usePlacesAutocomplete.ts Lines 137 to 155 in c9423dc
A possible enhancement would be to For now, if someone is facing a similar problem: |
@hossameldeen That's wired, the callback supposes should be triggered even if there's an error because the callback is given a |
Summary: Strangely, when calling Original message: @wellyshen Agreed, it's weird indeed.
const service = new google.maps.places.AutocompleteService();
try {
service.getPlacePredictions(
{
input: "restaurant",
types: ["establishment"],
location: new google.maps.LatLng({
lat: 50,
lng: 50,
}),
// radius: 123,
},
(predictions, status) => {
console.log("In callback", predictions, status);
}
);
} catch (e) {
console.log("In catch", e);
}
service
.getPlacePredictions({
input: "restaurant",
types: ["establishment"],
location: new google.maps.LatLng({
lat: 50,
lng: 50,
}),
// radius: 123,
})
?.then((predictions) => {
console.log("In then", predictions);
})
.catch((e) => {
console.log("In catch", e);
}); Update: Removed the point about status representing server errors only. The reference screenshot had "INVALID_REQUEST" as one of the possible values, actually. |
@hossameldeen Thank you for the detailed explanation. There's room for improving the error handling. Will spend time thinking about it. BTW, a PR for the error handling improvement is welcome as well. |
I'm using NextJS, load the script by <Script strategy="beforeInteractive" src="https://maps.googleapis.com/maps/api/js?key=KEY&libraries=places" /> I got |
That is probably because you have not waited to the api to load and tried to read google before it has ended. Also for those of you having problems, yes, as mentioned, the hook uses cache by default, so you might need to delete sessionstorage when you change the requestoptions (this could maybe be automatic somehow). Lastly, radius and location are deprecated now, so for someone wondering how it should be done now, an option could be using a circle with a radius and using locationBias like so:
|
can anyone help with the correct way of passing location and radius to requestOptions I tried usePlacesAutocomplete({ requestOptions: { types: "address", radius: 500, location: { lat: 8.7, 38.8 } }, debounce: 300, }); but its not working
The text was updated successfully, but these errors were encountered: