The Addressable module adds address fields to an object, and also has support for automatic geocoding.
- Marcus Nyeholt (marcus@silverstripe.com.au)
- SilverStripe 3.0+
In order to add simple address fields (address, suburb, city, postcode and
country) to an object, simply apply to Addressable
extension:
Page:
extensions:
- Addressable
In order to then render the full address into a template, you can use either
$FullAddress
to return a simple string, or $FullAddressHTML
to render
the address into a HTML <address>
tag.
You can define a global set of allowed states or countries using
Addressable::set_allowed_states()
and ::set_allowed_countries()
respectively. These can also be set per-instance using setAllowedStates()
and
setAllowedCountries()
.
If a single string is provided as a value, then this will be set as the field for all new objects and the user will not be presented with an input field. If the value is an array, the user will be presented with a dropdown field.
To add automatic geocoding to an Addressable
object when the address is
changed, simple apply the Geocodable
extension:
Page:
extensions:
- Geocodable
This will then use the Google Maps API to translate the address into a latitude
and longitude on save, and save it into the Lat
and Lng
fields. NOTE - to support
this, you must specify a Google app Server API key
GoogleGeocoding:
google_api_key: {your_google_server_api_key}
Allow different postcode regex (e.g. UK postcode with numbers and letters mixed) in config.yml
Addressable:
set_postcode_regex: '/^[0-9A-Za-z]+$/'