ayeo / geo
Calculate distance between two coordinates
Installs: 38 311
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 5
Forks: 0
Open Issues: 0
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is auto-updated.
Last update: 2024-11-18 07:37:30 UTC
README
Geo Distance
Simply way to calculate distance between two geo coordinates. There is Vincenty's formula used to do the calculations.
Install by Composer
require: "ayeo/geo": "1.0.*"
Example use
use Ayeo\Geo\Coordinate; use Ayeo\Geo\DistanceCalculator; //London: 51°30′N 0°07′W $london = new Coordinate\Degree(); $london->setLatitude(51, 30, 00, 'N'); $london->setLongitude(00, 07, 00, 'W'); //Buenos Aires: 34°35′S 58°55′W $buenosAires = new Coordinate\Degree(); $buenosAires->setLatitude(34, 35, 00, 'S'); $buenosAires->setLongitude(58, 55, 00, 'W'); $calculator = new DistanceCalculator(); $calculator->getDistance($london, $buenosAires); //result in meters
You can also use decimal coordinates
$example = new Coordinate\Decimal(53.2311, 18.1222);
DistanceCalculator allows to set radius, precision and multiplier. Default radius is set to Earth.
$calculator = new DistanceCalculator(); $calculator->setMultiplier(1); //default value, returns distance in meters $calculator->setMultiplier(1/1000); //kilometers $calculator->setMultiplier(1/1000000); //thousands of kilometers $calculator->setRadius(1737100); //Moon radius :) $calculator->setPrecision(0); //returns integers