The default Google plugin uses the geocoding API to suggest addresses. This is cheap and gives reasonable results.
However Google also offers a purpose built autocomplete API as part of Places (aka Maps) that gives way better results.
The following patch adds a new provider that supports this API.
Due to the decoupled nature of this functionality this provider bypasses the stock Drupal autocomplete widget in favor of the one provided by the Google Maps API. This is both for ease of use purposes, and also because attempting to implement this API using the Drupal autocomplete widget results in large numbers of expensive (as in money) queries in order to function.
When the google_autocomplete provider is enabled the default route and javascript file is not loaded and a Google autocomplete specific javascript file is loaded instead.
Note that if this patch is used on Drupal versions before 9.5.0 then the autocomplete widget will fail to load in address forms loaded via ajax due to this bug: #1988968: Drupal.ajax does not guarantee that "add new JS file to page" commands have finished before calling said JS
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3341452-add-google-places-autocomplete-2.patch | 11.38 KB | rhovland |
Comments
Comment #2
rhovlandComment #3
socialnicheguru commentedComment #4
chrisolof commentedHey guys - I believe we've got this in the latest beta by way of the fix to #3301846: Not properly working with Google maps provider.
See: https://git.drupalcode.org/project/address_autocomplete/-/blob/1.0.0-bet...
The current implementation utilizes autocomplete session tokens to avoid this, and I believe is then able to lean on the regular Drupal autocomplete functionality.
Unless I'm missing something here, I believe we can close this issue as a duplicate.
Comment #5
rhovlandAs part of updating this module in my project I will be required to revisit this. I will evaluate the changes with #3301846: Not properly working with Google maps provider at that time and update this issue with my results.
Comment #6
rhovlandThe new google maps provider is much simpler and works with the Places API so this is now no longer relevant.