Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 307 | All time: 7,349 This week: 49 |
Version | License | PHP version | Categories | |||
redbox-distance 1.2.5 | MIT/X Consortium ... | 5.4 | PHP 5, Web services, Geography |
Description | Author | |
This class can compute the distance between locations or zipcodes. |
Google API geocoder
Need to get lat/long and accuracy for address location
<?php |
This set of classes allow you to calculate the distance between Geo Locations or zipcodes. The information comes from the Google Maps API.
Use composer to install this package. Run the Composer command to install the latest stable version of Redbox-distance:
composer require redbox/distance
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
This package only requires the following:
Dit will also require PHPUnit 4.6 but that will be installed upon installing the package using composer.
Lets calculate the distance between Amsterdam and Rotterdam (Netherlands) using GeoLocations:
use Redbox\Distance;
$p1 = new Distance\GeoPoint(52.364533, 4.820374); /Amsterdam/
$p2 = new Distance\GeoPoint(51.925538, 4.471867); /Rotterdam/
$tool = new Distance\CalculateDistance();
$distance = $tool->setSource($p1)
->setDestination($p2)
->setUseSslVerifier(false)
->getDistanceInKM();
echo "<h2>Example 1</h2><br>";
echo 'The calculated distance is: '.$distance.' KM<br>';
Calculate the distance between Den Helder and Haarlem (Netherlands) using posalcodes:
use Redbox\Distance;
$p1 = new Distance\GeoZipCode('1781 GC'); /Den Helder/
$p2 = new Distance\GeoZipCode("2011 SR"); /Haarlem/
$tool = new Distance\CalculateDistance();
$distance = $tool->setSource($p1)
->setDestination($p2)
->setUseSslVerifier(false)
->getDistanceInKM();
echo "<h2>Example 2</h2><br>";
echo 'The calculated distance is: '.$distance.' KM';
Other available calculations are:
$distance->getDistanceInMiles();
and
$distance->getDistanceInYards();
If you get an error regarding SSL connectivity you might want to disable verify peer (CURLOPT_SSL_VERIFYPEER). The calculateDistance class offers a method to disable this. Consider using the setUseSslVerifier() method if needed like so.
$distance = $tool->setSource($p1)
...
->setUseSslVerifier(false)
...
Sometimes the postalcode feature could return wrong results. To battle this also add the country to the postalcode like so.
$p1 = new GeoZipCode('1781 GC Netherlands'); /Den Helder/
Redbox-distance is created and maintained by Johnny Mast. For feature requests and suggestions you could consider sending me an e-mail.
The MIT License
Copyright (c) 2017 Johnny Mast (mastjohnny@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Files (17) |
File | Role | Description | ||
---|---|---|---|---|
examples (5 files) | ||||
src (3 files) | ||||
tests (3 files) | ||||
.scrutinizer.yml | Data | Auxiliary data | ||
.travis.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE.md | Lic. | License | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Auxiliary data |
Files (17) | / | examples |
File | Role | Description |
---|---|---|
autoload.php | Aux. | Auxiliary script |
index.php | Example | Example script |
kilometer.php | Example | Example script |
miles.php | Example | Example script |
Yards.php | Example | Example script |
Files (17) | / | src |
File | Role | Description |
---|---|---|
CalculateDistance.php | Class | Class source |
GeoPoint.php | Class | Class source |
GeoZipCode.php | Class | Class source |
Files (17) | / | tests |
File | Role | Description |
---|---|---|
CalculateDistanceTest.php | Test | Unit test script |
GeoPointTest.php | Test | Unit test script |
GeoZipCodeTest.php | Test | Unit test script |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
Come checkout my Github page |
If you know an application of this package, send a message to the author to add a link here.