2017 © Pedro Peláez
 

class geo-location

Retrieve bounding coordinates, distances, longitude and latitude with GeoLocation.class.php

image

anthonymartin/geo-location

Retrieve bounding coordinates, distances, longitude and latitude with GeoLocation.class.php

  • Friday, February 16, 2018
  • by anthony
  • Repository
  • 16 Watchers
  • 124 Stars
  • 92,626 Installations
  • PHP
  • 6 Dependents
  • 1 Suggesters
  • 51 Forks
  • 2 Open issues
  • 3 Versions
  • 14 % Grown

The README.md

GeoLocation for PHP

GeoLocation for PHP offers convenient and easy to use methods for geocoding, geolocation and geometry functions in PHP., (*1)

Features include:, (*2)

  1. Retrieve bounding box coordinates. Just define a coordinate and the size of your bounding box.
  2. calculate distances between geopoints/coordinates
  3. Solve point in polygon problems (identify whether a given point is within the bounds of a polygon)

Examples

Get distance between two points:

<?php

use AnthonyMartin\GeoLocation\GeoPoint;

$geopointA = new GeoPoint(40.5187154, -74.4120953);
$geopointB = new GeoPoint(40.65, -73.95);
$geopointB = $geopointA->distanceTo($geopointB, 'miles');

Get latitude and longitude from address or location

In order to use this method, you'll need to register at Google Cloud Console and enable the Geocoding API, (*3)

<?php
use AnthonyMartin\GeoLocation\GeoPoint;

$geopoint = GeoPoint::fromAddress('New York, NY 10001', 'google-api-key-goes-here');
$latitude = $geopoint->getLatitude();
$longitude = $geopoint->getLongitude();

````

Get bounding box coordinates
--------------------------------------------------------
```php
<?php

use AnthonyMartin\GeoLocation\GeoPoint;

$geopointA = new GeoPoint(40.5187154, -74.4120953);
$boundingBox = $geopointA->boundingBox(3, 'miles');
$boundingBox->getMaxLatitude();
$boundingBox->getMaxLongitude();
$boundingBox->getMinLatitude();
$boundingBox->getMinLongitude();

How to find if coordinates/geopoint are in a polygon.

<?php

use AnthonyMartin\GeoLocation\GeoPoint;
use AnthonyMartin\GeoLocation\Polygon;

$geopointA = new GeoPoint(40.5187154, -74.4120953);
$polygon = Polygon::fromArray(array(
    [$lat1, $lon1],
    [$lat2, $lon2],
    [$lat3, $lon3],
    [$lat4, $lon4]
));
if ($geopointA->inPolygon($polygon)) {
  echo "GeoPoint is in Polygon!";
}

Transform bounding box coordinates into a polygon

<?php

use AnthonyMartin\GeoLocation\GeoPoint;

$geopointA = new GeoPoint(40.5187154, -74.4120953);
$boundingBox = $geopointA->boundingBox(5, 'mi');
$polygon = $boundingBox->toPolygon();

and now you can check if the GeoPoint is the polygon / bounding box:, (*4)

if ($geopointA->inPolygon($polygon)) {
  echo "GeoPoint is in Polygon / Bounding Box!";
}

Running Tests

Run the following from the project directory:, (*5)

./vendor/bin/phpunit tests

This is a collection of PHP classes written by Anthony Martin. Some of GeoLocation.php was derived from Java code that was originally published at http://JanMatuschek.de/LatitudeLongitudeBoundingCoordinates.
, (*6)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*7)

Copyright (c) 2019 Anthony Martin, (*8)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*9)

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*10)

The Versions

16/02 2018

dev-master

9999999-dev https://github.com/anthonymartin/GeoLocation.php

Retrieve bounding coordinates, distances, longitude and latitude with GeoLocation.class.php

  Sources   Download

MIT CC 3.0

The Requires

  • php >=5.3.0

 

geocoding geolocation bounding coordinates distances

17/09 2016

v1.0.1

1.0.1.0 https://github.com/anthonymartin/GeoLocation.php

Retrieve bounding coordinates, distances, longitude and latitude with GeoLocation.class.php

  Sources   Download

CC 3.0

The Requires

  • php >=5.3.0

 

geocoding geolocation bounding coordinates distances

25/10 2013

v1.0.0

1.0.0.0 https://github.com/anthonymartin/GeoLocation.php

Retrieve bounding coordinates, distances, longitude and latitude with GeoLocation.class.php

  Sources   Download

CC 3.0

The Requires

  • php >=5.3.0

 

geocoding geolocation bounding coordinates distances