PHP code example of anthonymartin / geo-location

1. Go to this page and download the library: Download anthonymartin/geo-location 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/ */

    

anthonymartin / geo-location example snippets




use AnthonyMartin\GeoLocation\GeoPoint;

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


use AnthonyMartin\GeoLocation\GeoPoint;

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




use AnthonyMartin\GeoLocation\GeoPoint;

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




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!";
}



use AnthonyMartin\GeoLocation\GeoPoint;

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

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