thewebmen / silverstripe-addressfield
Silverstripe module to create nested menus
Installs: 7 993
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 11
Forks: 2
Open Issues: 1
Requires
- jeroendesloovere/geolocation-php-api: 1.3.*
- silverstripe/cms: ^4.0@dev
- silverstripe/vendor-plugin: ^1.0
Requires (Dev)
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^3.0
README
Introduction
Address field with geolocation
Requirements
- Silverstripe CMS
^4 || ^5
- "jeroendesloovere/geolocation-php-api": "1.3.*"
Installation
composer require "thewebmen/silverstripe-addressfield" "dev-master"
Config
Add the Google Maps API key:
TheWebmen\Addressfield\Forms\GooglePlacesField: maps_api_key: 'API_KEY'
Or add the following variable to your .env
:
WDVLP_ADDRESSFIELD_MAPS_API_KEY='API_KEY'
Usage
Add all db fields to the db array:
private static $db = [
'City' => 'Varchar',
'Country' => 'Varchar',
'ZipCode' => 'Varchar',
'Street' => 'Varchar',
'StreetNumber' => 'Varchar',
'Latitude' => 'Varchar',
'Longitude' => 'Varchar'
];
Then add the field like any other field
public function updateCMSFields(FieldList $fields) { $fields->addFieldToTab('Root.Address', new AddressField($this->owner)); }
See the addressfield class for all constructor options.
Distance helper
The module comes with a distance helper to calculate the distance between two latitude/longitudes, example usage:
$list = ObjectWithLatitudeLongitude::get(); $list = TheWebmen\Addressfield\Helpers\DistanceHelper::addDistance($list, '52.2112', '5.9699'); $list = $list->sort('Distance'); foreach($list as $item){ var_dump($item->Distance); }
Todo
- Improve documentation