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.

usePlacesAutocompleteService not returning "geometry.location"

See original GitHub issue

This is the code I’m using to configure usePlacesAutocompleteService

const {
    placePredictions,
    getPlacePredictions,
    isPlacePredictionsLoading,
  } = useGoogle({
    apiKey: API_KEY,
    language: "en",
    debounce: 500,
    options: {
      types: [],
      componentRestrictions: { country: "ca" },
      fields: [
        "address_components",
        "geometry.location",
        "place_id",
        "formatted_address",
      ]
    }
  });

This is my response

description: "CN Tower, Bremner Boulevard, Toronto, ON, Canada"
matched_substrings: [{…}]
place_id: "ChIJmzrzi9Y0K4gRgXUc3sTY7RU"
reference: "ChIJmzrzi9Y0K4gRgXUc3sTY7RU"
structured_formatting: {main_text: 'CN Tower', main_text_matched_substrings: Array(1), secondary_text: 'Bremner Boulevard, Toronto, ON, Canada'}
terms: (5) [{…}, {…}, {…}, {…}, {…}]
types: (3) ['tourist_attraction', 'point_of_interest', 'establishment']

The intended response should be

address_components: (8) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
formatted_address: "290 Bremner Blvd, Toronto, ON M5V 3L9, Canada"
geometry: {location: _.Ee}
html_attributions: []
place_id: "ChIJmzrzi9Y0K4gRgXUc3sTY7RU"

Does google not allow such queries?

If so, is my only alternative (without using usePlacesWidget) to get LatLng via Google Map’s Geocoding / Places API?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
dcruz1990commented, Apr 25, 2022

Just call lat() and lng() using PlacesService

image

1reaction
lassoxocommented, Apr 28, 2022

Hey @dcruz1990 you should be able to get lat/lng by calling Google Map’s Geocoding / Places API separately or use a different library with geometry support. I was more concerned with the fact that I couldn’t utilize session token with this approach.

Keep in mind that whenever an Autocomplete request is called, a session token can be generated which is used along side of a subsequent Place Details call to save money!

usePlacesWidget provided by the package uses session token (and returns lat/lng) by default, however, you can’t customize the UI all that much.

Here are some documents on session tokens: https://developers.google.com/maps/documentation/places/web-service/session-tokens https://developers.google.com/maps/documentation/places/web-service/details#session_tokens

Best of luck!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Place Autocomplete | Maps JavaScript API - Google Developers
You can use the returned place ID with calls to the Places, Geocoding, Directions or Distance Matrix services. Note: The name property will...
Read more >
Google places api not returning geometry - Stack Overflow
Map worked fine and returned geometry yesterday, today it is just blank, ... addListener('place_changed', function () { var place = service.
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 >
Bug: Not receiving geometry.location for some addresses ...
Marie, ON, Canada" into places search box, click on the provided list item. 4. a place object is returned that doesn't contain a...
Read more >
react-native-google-places-autocomplete - npm
... "Google Places API Web Service" (NOT Android or iOS) in the console. ... from autocomplete if the place details api return not...
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