patrickkempff / location
A simple library for dealing with (geographical) locations.
dev-master
2016-08-15 10:42 UTC
Requires
- php: >=5.4.0
- beberlei/assert: ~2.5
Requires (Dev)
- friendsofphp/php-cs-fixer: ~1.11
- phpunit/phpunit: ~4.0|~5.0
- satooshi/php-coveralls: ~1.0
This package is not auto-updated.
Last update: 2024-12-21 21:19:52 UTC
README
A simple library for dealing with (geographical) locations.
use Location\Location; use Location\Coordinate\Coordinate2d; use Location\Distance\Haversine; // Amsterdam, NL. $amsterdam = new Location(new Coordinate2d(52.3079989, 4.9715451)); // Venlo, NL. $venlo = new Location(new Coordinate2d(51.3703748, 6.1724031)); // The distance between Venlo and Amsterdam is 132950 meters (132km 950m) // using the Haversine formula. $distance = $amsterdam->calculateDistanceFromLocation($venlo, new Haversine());
Please note that UTM, MGRS and USNG coordinate systems are not yet supported.
Installation
With Composer
$ composer require patrickkempff/location
{ "require": { "patrickkempff/location": "dev-master" } }
<?php require 'vendor/autoload.php'; use Location\Location; use Location\Coordinate\Coordinate2d; use Location\Distance\Haversine; // Amsterdam, NL. $amsterdam = new Location(new Coordinate2d(52.3079989, 4.9715451)); // Venlo, NL. $venlo = new Location(new Coordinate2d(51.3703748, 6.1724031)); // The distance between Venlo and Amsterdam is 132950 meters (132km 950m) // using the Haversine formula. $distance = $amsterdam->calculateDistanceFromLocation($venlo, new Haversine());
Manual installation
Please note that the recommend way to install Location is via composer. If you really want to install Location manually, you can download Location from the repo and unpack the files into your project.
<?php require 'path/to/Location.php'; require 'path/to/Coordinate/Coordinate2d.php'; require 'path/to/Distance/Haversine.php'; use Location\Location; use Location\Coordinate\Coordinate2d; use Location\Distance\Haversine; // Amsterdam, NL. $amsterdam = new Location(new Coordinate2d(52.3079989, 4.9715451)); // Venlo, NL. $venlo = new Location(new Coordinate2d(51.3703748, 6.1724031)); // The distance between Venlo and Amsterdam is 132950 meters (132km 950m) // using the Haversine formula. $distance = $amsterdam->calculateDistanceFromLocation($venlo, new Haversine());