Download the PHP package alkauni/distance-coordinate-calculator without Composer
On this page you can find all versions of the php package alkauni/distance-coordinate-calculator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alkauni/distance-coordinate-calculator
More information about alkauni/distance-coordinate-calculator
Files in alkauni/distance-coordinate-calculator
Package distance-coordinate-calculator
Short Description A Package to calculate the distance between two coordinate points
License MIT
Informations about the package distance-coordinate-calculator
Distance Coordinate Calculator Package
A feature-rich PHP & Laravel package to calculate geographical distance, check radius bounds, find nearest locations, and sort coordinate lists using the Haversine formula.
Features
- 📍 Calculate distance between two GPS coordinates (Latitude & Longitude).
- 📏 Multiple unit support: Kilometers (KM), Miles, Nautical Miles (N), and Meters (M).
- 🎯 Check if coordinates are within a specific radius (
isWithinRadius). - 🔎 Find the nearest location item from a list (
findNearest). - 📊 Sort location lists by distance (
sortByDistance). - 🏷️ Formatted output string with unit suffix (
calculateFormatted). - 🛡️ Latitude & Longitude validity checking (
isValidCoordinate). - ⚡ Laravel Package Auto-Discovery supported out of the box with Facade (
Distance).
Installation
You can install the package via composer:
Laravel Auto-Discovery
If you are using Laravel 8+, the Service Provider and Facade will be registered automatically via Package Auto-Discovery.
(Optional) Publish the configuration file:
This will publish distance.php to your config/ directory:
Usage
1. Basic Distance Calculation
2. Formatted Distance Output
Get a formatted string with rounded decimals and unit label:
3. Geofencing / Radius Check (isWithinRadius)
Check if a target location is within a given distance radius (e.g. for GPS attendance or delivery range):
4. Find Nearest Location (findNearest)
Find the closest branch/store from an array of locations:
5. Sort Locations by Distance (sortByDistance)
Sort an array or collection of location items by distance:
6. Validate Coordinates (isValidCoordinate)
Check if coordinates are within valid geographic latitude (-90 to 90) and longitude (-180 to 180):
Supported Units
| Unit Code | Description |
|---|---|
KM |
Kilometers (Default) |
Miles |
Miles |
N |
Nautical Miles |
M |
Meters |
Testing
Run tests using PHPUnit:
License
The MIT License (MIT). Please see License File for more information.