In order to use this service you must first create a project in Google Cloud Platform following this simple steps:
Open Google Cloud Platform and create a new project by clicking in the top left of the screen.
After creating the project, make sure it is selected in the dropdown.
On top left menu, navigate to API’s and services > Library. There are 2 libraries that you must enable in order to make the autocomplete work:
Open each one and click on Enable.
Navigate to API’s and services > Credentials and select Create credentials: API Key.
Google will autogenerate a new API key for you, write it down as you will need it later.
Once the API Key is created, click on Restrict Key.
In order to avoid other people/websites using your API keys, you must restrict its use to your domain.
Select URL HTTP References and add the domains that will be using this service. You can put an exact URL or use the asterisk (*) to target subdomains or paths.
In case you wondered, no, this service is not free. BUT Google provides a free 300€ budget for all new accounts which will be enough to cover the possible expenses.
You can check the actual pricing of the service here.
In order to get the free 300€ budget, you must create a new billing account and bind it to the project. Navigate to Billing through the top left menu to do it.
Add a simple text input in your form and give it an ID. This ID will be used to target the element in the code.
Copy this custom code, replace the following elements and put it in the before </body> tag of your page/project: