Address field with geolocation
composer require "thewebmen/silverstripe-addressfield" "dev-master"
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.
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);
}
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem