Laravel Geographical Calculator

Packages

December 17th, 2021

laravel-geographical-calculator.png

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.

1use \KMLaravel\GeographicalCalculator\Facade\GeoFacade;
2 
3$distance = GeoFacade::setPoint([22, 37])
4 ->setOptions(['units' => ['km']])
5 // you can set unlimited lat/long points.
6 ->setPoint([33, 40])
7 // get the calculated distance between each point
8 ->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:

1// Get the calculated center between these points.
2$center = GeoFacade::setPoint([22, 37])
3 // you can set unlimited points.
4 ->setPoint([33, 40])
5 ->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.

Laravel News Partners