Laravel Geographical Calculator

Packages

December 17th, 2021

Laravel Geographical Calculator

Laravel Geographical Calculator helps you implement geographical calculation with several algorithms that help you deal with coordinates.

This package has two primary uses: getting the distance between a set of coordinates and getting the center between two or more coordinates.

First, here's an example of getting the distance between multiple sets of latitude and longitude points. The GeoFacade accepts various sets of points and calculates the distance between point one and point two, then points two and three, and so on.

use \KMLaravel\GeographicalCalculator\Facade\GeoFacade;
 
$distance = GeoFacade::setPoint([22, 37])
->setOptions(['units' => ['km']])
// you can set unlimited lat/long points.
->setPoint([33, 40])
// get the calculated distance between each point
->getDistance();

You can get the center between two sets of lat/long points using the getCenter() method. Like the getDistance() method, you can call setPoint() multiple times and it will calculate the center of multiple sets of points:

// Get the calculated center between these points.
$center = GeoFacade::setPoint([22, 37])
// you can set unlimited points.
->setPoint([33, 40])
->getCenter();

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.