Google Maps Places Autocomplete missing geometry

前端 未结 3 793
有刺的猬
有刺的猬 2021-01-13 08:42

The Google Maps Places Autocomplete does not work as expected anymore.

https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete

相关标签:
3条回答
  • 2021-01-13 09:24

    Take a look at the beginning of the function:

    if (!place.geometry) {
      return;
    }
    

    A PlaceResult may, but must not have a geometry-property.

    To clarify how the autocomplete works:

    when you type something, the API will request the predictions(to populate the dropdown). Only when you select a place from the dropdown it requests the data(including the geometry) for the particular place.

    Obviously there are inconsistencies of the used data(the API shouldn't suggest a place where no informations are accessible), but that's how it is, it may happen that you get a prediction without a place.

    Workaround: AFAIK no

    0 讨论(0)
  • 2021-01-13 09:37

    Please be sure you set 'geometry' field in autocomplete like this:

    autocomplete.setFields(['address_component', 'geometry']);

    0 讨论(0)
  • 2021-01-13 09:44

    Looks like it has been fixed by Google :)

    0 讨论(0)
提交回复
热议问题