Fetches the geo position (lon,lat) from google maps api. Can be used as free address input field or referenced to other address fields in form
- Silverstripe 3.*
composer require "nblum/silverstripe-geocodefield"
- Download and copy module in SilverStripe root directory
Basic Example:
private static $db = array(
'Geodata' => 'Json'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
//create a GeoCodeField field
$fields->addFieldToTab('Root.Main', new GeoCodeField('Geodata'));
return $fields;
}
Example with referenced address fields:
private static $db = array(
'Street' => 'Varchar(64)',
'City' => 'Varchar(64)',
'Geodata' => 'Json'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new TextField('Street'));
$fields->addFieldToTab('Root.Main', new TextField('City'));
//create a GeoCodeField field
$field = new GeoCodeField('Geodata', 'Geo Position');
$field->addAddressReference('Street');
$field->addAddressReference('City');
$field->setAddressNotEditable();
$fields->addFieldToTab('Root.Main', $field);
return $fields;
}