question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

There is a way to specified `fields` using usePlacesAutocompleteService?

See original GitHub issue

I’m using usePlacesAutocompleteService and I wanna specified fields to return in predictions. Is it possible? Or even use the getDetails

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
ErrorProcommented, May 27, 2021

@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!

1reaction
narcellocommented, Jun 3, 2021

@ErrorPro Don’t worry, it’s working 😃 thank you again 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Places Autocomplete Service | Maps JavaScript API
Stay organized with collections Save and categorize content based on your preferences. Dismiss Got it.
Read more >
How to Use Places Autocomplete Google API - W3docs
The service can be used to provide an autocomplete functionality for text-based geographic searches by returning places such as businesses, addresses and points ......
Read more >
wellyshen/use-places-autocomplete: React hook for ... - GitHub
I just show you how does it work via the minimal example. However you can build a UX rich autocomplete component, like WAI-ARIA...
Read more >
Google Places Autocomplete Force Selection - Stack Overflow
Every time a location is picked from the Auto complete list, we populate some hidden fields with some fields coming from the JSON...
Read more >
Integrating Google Places Autocomplete API in a React App
Let's see how to use one of the libraries provided by the Google Maps ... the Places Autocomplete instance and bind it to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found