1. Go to this page and download the library: Download philiprehberger/php-geo library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
philiprehberger / php-geo example snippets
use PhilipRehberger\Geo\Coordinate;
use PhilipRehberger\Geo\Geo;
$nyc = new Coordinate(40.7128, -74.0060);
$la = new Coordinate(33.9425, -118.4081);
$km = Geo::distance($nyc, $la); // ~3944 km
$miles = Geo::distance($nyc, $la, 'mi'); // ~2451 mi
$km = Geo::distanceVincenty($nyc, $la); // More accurate for long distances
$polygon = [
new Coordinate(40.800, -73.970),
new Coordinate(40.800, -73.950),
new Coordinate(40.760, -73.950),
new Coordinate(40.760, -73.970),
];
$point = new Coordinate(40.780, -73.960);
Geo::contains($polygon, $point); // true
$bearing = Geo::bearing($nyc, $la); // Initial bearing in degrees (0-360)
$coord = new Coordinate(40.7128, -74.0060);
$elevated = $coord->withElevation(100.5); // New Coordinate with elevation
$elevated->getElevation(); // 100.5
$coord->getElevation(); // null (original unchanged)
$polygon = [
new Coordinate(0.0, 0.0),
new Coordinate(0.0, 1.0),
new Coordinate(1.0, 1.0),
new Coordinate(1.0, 0.0),
];
$area = Geo::area($polygon); // Area in square meters
$coord = new Coordinate(57.64911, 10.40744);
$hash = Geo::encodeGeohash($coord); // 'u4pruydqqvj8'
$decoded = Geo::decodeGeohash($hash); // Coordinate near original
$bounds = Geo::geohashBounds($hash); // BoundingBox of geohash cell
$coordinates = [
new Coordinate(38.5, -120.2),
new Coordinate(40.7, -120.95),
new Coordinate(43.252, -126.453),
];
$encoded = Geo::encodePolyline($coordinates); // '_p~iF~ps|U_ulLnnqC_mqNvxq`@'
$decoded = Geo::decodePolyline($encoded); // Array of Coordinate objects
$route = [
new Coordinate(40.7128, -74.0060),
new Coordinate(41.8781, -87.6298),
new Coordinate(33.9425, -118.4081),
];
$total = Geo::routeDistance($route); // Total distance in km
Geo::distance($a, $b, 'mi'); // miles
Geo::distance($a, $b, 'm'); // meters
Geo::distance($a, $b, 'nmi'); // nautical miles
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.