|
Purpose: configure Google Maps address autocomplete for the Add New Client popup, store the selected address details, and keep the setup secure and maintainable. |
1. What this integration does
· Adds Google-powered address suggestions to the Add New Client form.
· Lets the user choose a result, then fills Address, City, County/State, Postcode, Country, Latitude, and Longitude.
· Uses the module setting “Address Provider = Google” together with a Google API key.
· Biases or restricts results to the United Kingdom when your module setting is set to GB.
2. Prerequisites
· A Google Cloud project with billing enabled.
· Maps JavaScript API enabled in that project.
· Places API enabled in that project.
· A production API key restricted to your website domain(s).
· A FlexiShop module settings page with a Google provider option and an API key field.
3. Recommended module settings
|
Setting |
Recommended value |
Notes |
|
Address provider |
|
Switches autocomplete from OpenStreetMap to Google. |
|
Google Maps API key |
Your browser key |
Use a key restricted to your site domain. |
|
Google country code |
GB |
Biases or restricts autocomplete to United Kingdom results. |
|
Default country |
United Kingdom |
Keep this as the customer form default. |
|
Language |
en-GB |
Optional, but useful for UK formatting. |
4. Google Cloud setup
· Open Google Cloud Console and select or create the project you want to use for this module.
· Attach a billing account to the project.
· Enable both Maps JavaScript API and Places API.
· Create an API key for browser use.
· Add HTTP referrer restrictions for your live domain and any staging domain.
· Restrict the key so it is only allowed to call the APIs this module needs.
5. Script loading example
Load the Maps JavaScript API with the places library. Replace YOUR_API_KEY with the key stored in module settings.
|
<script async |
6. Example integration for the Add New Client modal
This example keeps your existing Address input and attaches Google autocomplete when the modal opens.
|
<input type="text" id="client_address" name="address" class="form-control"> |
7. Server-side handling
· Do not rely only on the browser. On save, force safe defaults for latitude and longitude when the request is empty.
· Keep country defaulting to United Kingdom on the server as a fallback even if the UI does not send it.
· Create the customer first, then create the contact in a second step linked to that customer ID.
· Validate that the submitted key fields exist before calling any insert logic.
|
$data['country'] = !empty($data['country']) ? $data['country'] : $uk_country_id; |
8. Testing checklist
· Open New Repair Job and click Add New Client.
· Confirm the country defaults to United Kingdom before typing an address.
· Start typing a UK address and check that suggestions appear.
· Select a result and confirm Address, City, County/State, Postcode, Latitude, and Longitude are filled.
· Save the customer and confirm only one customer record is created.
· Confirm the contact is created afterwards and linked to the same customer.
· Confirm the new customer is auto-selected in the repair job form.
9. Troubleshooting
|
Problem |
What to check |
|
No suggestions appear |
Check that Maps JavaScript API and Places API are enabled, the API key is valid, and the browser console is not showing a referrer or billing error. |
|
Works on staging but not live |
Update HTTP referrer restrictions to include the live domain and any www / non-www variations. |
|
Latitude still null |
Confirm hidden latitude and longitude inputs exist in the form and the server still forces 0 defaults. |
|
Country is not UK by default |
Set the UI default to GB and also set the server fallback to the United Kingdom country ID from the Perfex countries table. |
|
Unexpected non-UK results |
Check componentRestrictions country = gb and confirm your module setting stores GB, not UK. |
10. Security and policy notes
· Use a browser key only for the browser-side JavaScript integration.
· Keep server-side web-service keys private and never expose them in client-side code.
· Restrict production keys by HTTP referrer and by allowed APIs.
· Review Google Maps attribution, privacy policy, and terms requirements before going live.
11. Suggested settings text for your module
|
Address Provider: Google |
12. Official references
· Google Maps Platform — Getting started
· Set up the Maps JavaScript API
· Set up the Places API (New)
· Place Autocomplete Widget / Place Autocomplete Overview
· Google Maps Platform security guidance
· Policies and attributions for Maps JavaScript API