loveduckie/silverstripe-google-maps-field

A SilverStripe module for integrating Google Maps Places API as part of the CMS.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Type:silverstripe-vendormodule

5.x-dev 2024-11-28 16:36 UTC

This package is auto-updated.

Last update: 2024-11-28 16:36:42 UTC


README

A Silverstripe module that provides an input field extension for collecting postal addresses using Google Maps' Autocomplete functionality from the Places API. This extension offers users a streamlined way to enter accurate addresses by suggesting address completions directly within the input field.

Features

  • Autocomplete: As users type, Google Maps Autocomplete provides address suggestions.
  • Field Customization: Easily integrates with Silverstripe’s form fields and can be customized to fit specific field requirements.
  • Real-time Address Validation: Ensures that addresses are valid and formatted properly based on Google Maps data.

Requirements

  • Silverstripe CMS 4.x or later
  • Google Maps API Key (with Places API enabled)

Installation

  1. Install via Composer:

    composer require loveduckie/silverstripe-google-maps-field
  2. Google Maps API Key: Obtain an API key from the Google Cloud Console. Ensure that the Places API is enabled.

  3. Configuration: In your Silverstripe project, add the Google Maps API key to your .env file:

    GOOGLE_MAPS_API_KEY="YOUR_API_KEY"
    
  4. Build the Project: Run dev/build to ensure the module is loaded properly.

Usage

  1. Add Field to Form: In your form class, add the address autocomplete field as shown below:

    use LoveDuckie\SilverStripe\GoogleMapsField;
    
    $form->addField(
        GoogleMapsAutocompleteAddressField::create('Address', 'Postal Address')
    );
  2. Customize Field Options:

    • You can specify additional options like the country filter, address type, and more by configuring the field in the Silverstripe backend or by setting options directly in the form.
  3. Styling: Customize the look and feel of the autocomplete field with CSS to match your site’s design.

Configuration Options

Configure the following settings in your YAML configuration file:

LoveDuckie\SilverStripe\GoogleMapsField:
  default_country: "US"  # Set the default country for address suggestions
  address_components:    # Specify which address components to retrieve
    - street_number
    - route
    - locality
    - administrative_area_level_1
    - country
    - postal_code

Screenshots

TBD

Troubleshooting

  • Ensure that the Google Maps API key has the correct permissions for the Places API.
  • Verify that your Silverstripe cache is cleared after installation.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributions

Contributions are welcome! Please submit issues or pull requests to help improve this module.

Acknowledgments

This module utilizes the Google Maps API to deliver accurate address suggestions and facilitate seamless form input.