A general purpose geo library.

v0.1.0 2014-02-23 03:53 UTC

This package is auto-updated.

Last update: 2022-01-12 15:57:58 UTC


A general purpose geo library for PHP.

Build Status Scrutinizer Code Quality Code Coverage

Latest Stable Version Total Downloads Latest Unstable Version License

Dependency Status


This package uses composer so you can just add nubs/coordinator as a dependency to your composer.json file or execute the following command:

composer require nubs/coordinator



A coordinate is a latitude/longitude pair. They are created using radians, although the CoordinateFactory and various CoordinateSystem's discussed below can help create them as well.

Creating a coordinate

Using the constructor, you can create a coordinate using radians.

use Nubs\Coordinator\Coordinate;

$coordinate = new Coordinate($latitudeInRadians, $longitudeInRadians);
Using the Coordinate Factory

Using the CoordinateFactory, you can create coordinates in a similar way.

use Nubs\Coordinator\CoordinateFactory;

$coordinateFactory = new CoordinateFactory();
$coordinate = $coordinateFactory->createFromRadians(

The CoordinateFactory, however, can also create coordinates from latitude and longitude specified in degrees.

use Nubs\Coordinator\CoordinateFactory;

$coordinateFactory = new CoordinateFactory();
$coordinate = $coordinateFactory->createFromDegrees(

Accessing Coordinate Data

The latitude and longitude in radians can be pulled back out of the Coordinate.

echo "Latitude: {$coordinate->latitudeInRadians()}\n";
echo "Longitude: {$coordinate->longitudeInRadians()}\n";

The latitude and longitude can also be pulled back out in degrees.

echo "Latitude: {$coordinate->latitudeInDegrees()}\n";
echo "Longitude: {$coordinate->longitudeInDegrees()}\n";

A __toString() helper also exists that returns the coordinate in degrees.

echo (string)$coordinate;

Coordinate Systems

Coordinate systems help convert coordinates from other systems/projections into standard latitude/longitude. Currently the Mercator projection is defined.

Coordinate systems operate on a given Spheroid, and there is an Earth spheroid defined.

Converting Coordinates

A coordinate in a coordinate system can be converted to degrees/radians.

use Nubs\Coordinator\CoordinateFactory;
use Nubs\Coordinator\CoordinateSystem\Mercator;
use Nubs\Coordinator\Spheroid\Earth;

$mercator = new Mercator(new Earth(), new CoordinateFactory());
$coordinate = $mercator->loadCoordinate($xCoordinate, $yCoordinate);
echo (string)$coordinate;


Coordinator is licensed under the MIT license. See LICENSE for the full license text.