Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeroendesloovere/distance
This Distance PHP class can calculate the distance between two latitude/longitude locations using Math functions in PHP. No external API's are called.
https://github.com/jeroendesloovere/distance
distance latitude longitude php
Last synced: 2 months ago
JSON representation
This Distance PHP class can calculate the distance between two latitude/longitude locations using Math functions in PHP. No external API's are called.
- Host: GitHub
- URL: https://github.com/jeroendesloovere/distance
- Owner: jeroendesloovere
- License: mit
- Created: 2013-08-26T09:11:23.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-03-08T05:16:57.000Z (almost 2 years ago)
- Last Synced: 2024-10-11T13:12:19.981Z (3 months ago)
- Topics: distance, latitude, longitude, php
- Language: PHP
- Homepage: https://packagist.org/packages/jeroendesloovere/distance
- Size: 23.4 KB
- Stars: 35
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Distance class
[![Latest Stable Version](http://img.shields.io/packagist/v/jeroendesloovere/distance.svg)](https://packagist.org/packages/jeroendesloovere/distance)
[![License](http://img.shields.io/badge/license-MIT-lightgrey.svg)](https://github.com/jeroendesloovere/distance/blob/master/LICENSE)
[![Build Status](http://img.shields.io/travis/jeroendesloovere/distance.svg)](https://travis-ci.org/jeroendesloovere/distance)Get distance between two locations using PHP. The distance is getting calculated based on latitude and logitude variables and without using any other external class.
## Usage
### Installing using Composer
When using [Composer](https://getcomposer.org) you can always load in the latest version.
```bash
{
"require": {
"jeroendesloovere/distance": "1.0.*"
}
}
```
> Check [in Packagist](https://packagist.org/packages/jeroendesloovere/distance).### Example
**Setting our example data**
```php
use JeroenDesloovere\Distance\Distance;// first location
$latitude1 = '50.8538510000';
$longitude1 = '3.3550450000';// second location
$latitude2 = '50.8325600000';
$longitude2 = '3.4787650000';
```**Get distance between two locations**
```php
$distance = Distance::between(
$latitude1,
$longitude1,
$latitude2,
$longitude2
);// dump data
echo 'Distance between the two locations = ' . $distance . ' km';
```**Get closest distance from location 1 to one of the two locations (2 and 3)**
```php
// third location
$latitude3 = '50.8865040000';
$longitude3 = '3.4320850000';// define multiple items
$items = array(
array(
'title' => 'location 2',
'latitude' => $latitude2,
'longitude' => $longitude2
),
array(
'title' => 'location 3',
'latitude' => $latitude3,
'longitude' => $longitude3
)
);$distance = Distance::getClosest(
$latitude1,
$longitude1,
$items
);// dump data
echo 'The closest location to location 1 is ' . $distance['title'] . ' and the distance between them is ' . $distance['distance'] . ' km';
```## Documentation
The class is well documented inline. If you use a decent IDE you'll see that each method is documented with PHPDoc.
## Contributing
It would be great if you could help us improve this class. GitHub does a great job in managing collaboration by providing different tools, the only thing you need is a [GitHub](http://github.com) login.
* Use **Pull requests** to add or update code
* **Issues** for bug reporting or code discussions
* Or regarding documentation and how-to's, check out **Wiki**
More info on how to work with GitHub on help.github.com.## License
The module is licensed under [MIT](./LICENSE.md). In short, this license allows you to do everything as long as the copyright statement stays present.