Closed narcello closed 3 years ago
For the AutocompleteService
only these options available, no fields option available. Regarding the getDetails
service, to be able to call this method you need to have different service to be available. I was going to add initiation of this service and bound it together with usePlacesAutocompleteService
. If you could give me a bit more context about why you need to do I could build this ASAP. @narcello
Closing this issue for now but I'd love to hear back from you @narcello
I have the same problem. In my case, I need getDetails
in order to fetch the coordinates. Besides city, region and country I need also latitude and longitutde and I see that getPlacePredictions()
doesn't return the coordinates.
@adybuciuman Hey! getDetails
is a different service(places-service) from google API. The mentioned hook only works with the places-autocomplete-service. I had an idea to initiate the places-service instance as well inside usePlacesAutocompleteService
and return it so that anyone can use it as part of usePlacesAutocompleteService
hook. Let me know if that's something you' like to have to tell me more about how you would like to use it. Thanks!
@ErrorPro Thanks for answer me. My goal is get the cities and I want to get coordinates and formatted_address as well, to fill address form automatically with postal code, street, venue, etc.
@narcello @adybuciuman hey guys! If the usePlacesAutocompleteService
returns placesService
which you can call at any place in your component will that help you to solve your cases? for example
const { placePredictions, getPlacePredictions, placesService } =
usePlacesService({
apiKey: process.env.REACT_APP_GOOGLE,
});
useEffect(() => {
placesService. getDetails({ placeId: placePredictions[0].place_id, fields: ['geometry.location'] })
.then(res => console.log(res))
}, [placePredictions]);
or you can call this line when user selects a location from your autocompleteonClick={() => placesService. getDetails({ placeId: el.place_id, fields: ['geometry.location'] })}
. In this case you can use an autocomplete session feature and only pay for a single session.
Let me know if there's any other way you'd prefer it to be. Thanks!
How can we get the coordinates in the meantime?
@thebiltheory You can get the placeid from the placePredictions
and then you need to create a placesService
yourself to get it. It's a bit of hassle and overhead I know. I hope that the proposition I described above will find its support among people who use this library so I can implement that ASAP. I am trying to see if there's any other option to achieve the same result but it seems there's not. Let me know your thoughts
@ErrorPro Nice, thanks. I just seen and I'll test it today. Thank you, I'll let you know about the tests :)
@ErrorPro Worked, but I had to pass a function callback to get the result from getDetails, little bit different from here but it's fine man, thanks again :)
@narcello Yes it's a bit different cuz I supposed that the getDetails
would return a promise but it does not :(
I will write a wrapper around its interface to promisify
sometimes later, it will be backwards-compatible. Hope the current implementation will work for a while :) Cheers!
@ErrorPro Don't worry, it's working :) thank you again 🎉
I'm using usePlacesAutocompleteService and I wanna specified
fields
to return in predictions. Is it possible? Or even use the getDetails