Geokit is a PHP toolkit to solve geo-related tasks like:
Install through composer. Check the
packagist page for all
available versions.
{
"require": {
"geokit/geokit": "0.2.*@dev"
}
}
A LatLng instance represents a geographical point in latitude/longitude
coordinates.
$latLng = new Geokit\LatLng(1, 2);
$latitude = $latLng->getLatitude();
// or
$latitude = $latLng['latitude'];
$longitude = $latLng->getLongitude();
// or
$longitude = $latLng['longitude'];
Alternatively, you can create a LatLng instance through its static normalize
method. This method takes anything which looks like a coordinate and generates a
LatLng object from it.
$latLng = Geokit\LatLng::normalize('1 2');
$latLng = Geokit\LatLng::normalize('1, 2');
$latLng = Geokit\LatLng::normalize(array('latitude' => 1, 'longitude' => 2));
$latLng = Geokit\LatLng::normalize(array('lat' => 1, 'lng' => 2));
$latLng = Geokit\LatLng::normalize(array('lat' => 1, 'lon' => 2));
$latLng = Geokit\LatLng::normalize(array(1, 2));
A Bounds instance represents a rectangle in geographical coordinates, including
one that crosses the 180 degrees longitudinal meridian.
It is constructed from its left/bottom (south-west) and right-top (north-east)
corner points.
$southWest = new Geokit\LatLng(1, 2);
$northEast = new Geokit\LatLng(1, 2);
$bounds = new Geokit\Bounds($southWest, $northEast);
$southWestLatLng = $bounds->getSouthWest();
// or
$southWestLatLng = $bounds['south_west'];
$northEastLatLng = $bounds->getNorthEast();
// or
$northEastLatLng = $bounds['north_east'];
$centerLatLng = $bounds->getCenter();
// or
$centerLatLng = $bounds['center'];
$spanLatLng = $bounds->getSpan();
// or
$spanLatLng = $bounds['span'];
$boolean = $bounds->contains($latLng);
$newBounds = $bounds->extend($latLng);
$newBounds = $bounds->union($otherBounds);
Alternatively, you can create a Bounds instance through its static normalize
method. This method takes anything which looks like bounds and generates a
Bounds object from it.
$latLng = Geokit\Bounds::normalize('1 2 3 4');
$latLng = Geokit\Bounds::normalize('1 2, 3 4');
$latLng = Geokit\Bounds::normalize('1, 2, 3, 4');
$latLng = Geokit\Bounds::normalize(array('south_west' => $southWestLatLng, 'north_east' => $northEastLatLng));
$latLng = Geokit\Bounds::normalize(array('south_west' => array(1, 2), 'north_east' => array(3, 4)));
$latLng = Geokit\Bounds::normalize(array('southwest' => $southWestLatLng, 'northeast' => $northEastLatLng));
$latLng = Geokit\Bounds::normalize(array('southWest' => $southWestLatLng, 'northEast' => $northEastLatLng));
$latLng = Geokit\Bounds::normalize(array($southWestLatLng, $northEastLatLng));
A Distance instance allows for a convenient representation of a distance unit of
measure.
$distance = new Geokit\Distance(1000);
// or
$distance = new Geokit\Distance(1, Geokit\Distance::UNIT_KILOMETERS);
$meters = $distance->meters();
$kilometers = $distance->kilometers();
$miles = $distance->miles();
$feet = $distance->feet();
$nauticalMiles = $distance->nautical();
Alternatively, you can create a Distance instance through its static normalize
method. This method takes anything which looks like distance and generates a
Distance object from it.
$distance = Geokit\Distance::normalize(1000); // Defaults to meters
$distance = Geokit\Distance::normalize('1000m');
$distance = Geokit\Distance::normalize('1km');
$distance = Geokit\Distance::normalize('100 miles');
$distance = Geokit\Distance::normalize('1 foot');
$distance = Geokit\Distance::normalize('234nm');
Geokit is released under the MIT License.
Geokit has been inspired and/or contains ported code from the following
libraries: