Skip to content

jordiwes/GoogleMapsTools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoogleMapsTools

PHP wrapper for Google Maps API

Author

Simeon Goranov - sgoranov@gmail.com

Installation

Update your composer.json adding following

"require": {
    "sgoranov/google-maps-tools": "dev-master"
},

Run composer update to fetch and install

php composer.phar update

Usage

Use the Google Maps Geocoding API call to search by address:

$geocode = new Geocode('Car Osvoboditel 13, Sofia, Bulgaria');
$geocode->execute();
$point = $geocode->getFirstPoint();

The point is defined as latitude and longitude:

$latitude = $point->getLatitude();
$longitude = $point->getLongitude();

Use Google Maps Distancematrix API call to calculate the distance between two points:

$dmatrix = new Distancematrix($startPoint, $endPoint);
try {
    $result = $dmatrix->fetch();
} catch (ApiException $e) {
    throw new \InvalidArgumentException('Unable to calculate the distance');
}

Use DistanceCalc library to calculate the distance between multiple points:

$calc = new DistanceCalc();

$geocode = new Geocode('Car Osvoboditel 13, Sofia, Bulgaria');
$geocode->execute();
$point = $geocode->getFirstPoint();
$calc->addPoint($point);

$geocode = new Geocode('Ianko Sakazov 1, Sofia, Bulgaria');
$geocode->execute();
$point = $geocode->getFirstPoint();
$calc->addPoint($point);

$geocode = new Geocode('Georgi Rakovski 96, Sofia, Bulgaria');
$geocode->execute();
$point = $geocode->getFirstPoint();
$calc->addPoint($point);

$distance = $calc->calculate();

Unit testing

To run all the tests execute following from GoogleMapsTools/src sirectory

phpunit GoogleMapsTools/Test/AllTests.php

To run one specific test only execute the following from GoogleMapsTools/src sirectory

phpunit GoogleMapsTools/Test/Api/DistancematrixTest.php

About

PHP wrapper for Google Maps API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages