salmanzafar / laravel-geo-fence
A Laravel Library to calculate distance between two longitude and latitudes
Fund package maintenance!
Patreon
www.buymeacoffee.com/salmanzafar949
Installs: 6 432
Dependents: 1
Suggesters: 0
Security: 0
Stars: 15
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^5.4.0 || ^7.0 || ^7.1 || ^7.2 || ^7.3 || ^7.4
Requires (Dev)
- laravel/framework: ^5.0 || ^6.0 || ^7.0 || ^8.0
README
A Laravel 5 and Laravel 6 package to calculate distance between two longitude and latitudes
Installation
composer require salmanzafar/laravel-geo-fence
Enable the package (Optional)
This package implements Laravel auto-discovery feature. After you install it the package provider and facade are added automatically for laravel >= 5.5.
This step is only required if you are using laravel version <5.5
To declare the provider and/or alias explicitly, then add the service provider to your config/app.php:
'providers' => [
Salman\GeoFence\GeoFenceServiceProvider::class,
];
And then add the alias to your config/app.php:
'aliases' => [
'GeoFence' => \Salman\GeoFence\Facades\GeoFence::class,
];
Configuration
Publish the configuration file
php artisan vendor:publish --provider="Salman\GeoFence\GeoFenceServiceProvider"
Config/geofence.php
return [
"unit" => "k" // get result in kilometers
// change unit to M/m to get result in Miles
];
Using in Controller
use Salman\GeoFence\Service\GeoFenceCalculator;
public function distance()
{
$d_calculator = new GeoFenceCalculator();
$distance = $d_calculator->CalculateDistance('38.199020', '-77.969658', '37.090240', '-95.712891');
return $distance;
}
output: 1564.6
Measure Distance using Facade in Controller
use use GeoFence;
public function distance()
{
$distance = GeoFence::CalculateDistance('38.199020', '-77.969658', '37.090240', '-95.712891');
return $distance;
}
output: 1564.6
Measure Distance using command
php artisan geo:fence ************************************************** * Welcome To Geo Fence Calculator * ************************************************** Enter latitude 1: : > 38.199020 Enter latitude 2: : > 37.090240 Enter Longitude 1: : > -77.969658 Enter Longitude 2: : > -95.712891 Enter Unit k\M: : > K Measured distance is: 1564.6 K