PHPackages                             metasyntactical/google-directions-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. metasyntactical/google-directions-client

ActiveLibrary[API Development](/categories/api)

metasyntactical/google-directions-client
========================================

Client for Google Directions API to add interpolated points to a route consisting of given coordinates.

v2.0.0(7y ago)2278[1 issues](https://github.com/MetaSyntactical/google-directions-client/issues)MITPHPPHP ^7.1

Since Jan 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/MetaSyntactical/google-directions-client)[ Packagist](https://packagist.org/packages/metasyntactical/google-directions-client)[ RSS](/packages/metasyntactical-google-directions-client/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (5)Dependencies (7)Versions (6)Used By (0)

README
======

[](#readme)

[![Build Status](https://camo.githubusercontent.com/a43f61c69d0ac3b98e650039b1c0db5c8cdc3ebc0bac3f504d1fa622f6020771/68747470733a2f2f7472617669732d63692e6f72672f4d65746153796e746163746963616c2f676f6f676c652d646972656374696f6e732d636c69656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/MetaSyntactical/google-directions-client)[![Downloads this Month](https://camo.githubusercontent.com/593d25974a9fcd4303eaedd02d20b51df5608a4b6ea4fccf48510d319cb1dd6d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d65746173796e746163746963616c2f676f6f676c652d646972656374696f6e732d636c69656e742e7376673f7374796c653d666c6174)](https://packagist.org/packages/metasyntactical/google-directions-client)[![Latest stable](https://camo.githubusercontent.com/2b551742d31aee657a980c9666904fea3a5d9a8528faa1dd30bbef5b3bd5db70/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d65746173796e746163746963616c2f676f6f676c652d646972656374696f6e732d636c69656e742e7376673f7374796c653d666c6174266c6162656c3d737461626c65)](https://packagist.org/packages/metasyntactical/google-directions-client)[![Latest dev](https://camo.githubusercontent.com/ae34828271e3681d3206ad6b551c581a873ee2df10edea1e2842e24c8df34c5f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6d65746173796e746163746963616c2f676f6f676c652d646972656374696f6e732d636c69656e742e7376673f7374796c653d666c6174266c6162656c3d756e737461626c65)](https://packagist.org/packages/metasyntactical/google-directions-client)[![License](https://camo.githubusercontent.com/782dff204ea67a8643089aa423ad0d7dabbb4870797cad1622ffa8d9127f77d8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d65746173796e746163746963616c2f676f6f676c652d646972656374696f6e732d636c69656e742e7376673f7374796c653d666c6174266c6162656c3d6c6963656e7365)](https://packagist.org/packages/metasyntactical/google-directions-client)[![Code Climate](https://camo.githubusercontent.com/d64c6e6294f6b3e51fb414ee4bc3ff3859f7e953dee95ce13b362a6076356833/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4d65746153796e746163746963616c2f676f6f676c652d646972656374696f6e732d636c69656e742f6261646765732f6770612e737667)](https://codeclimate.com/github/MetaSyntactical/google-directions-client)[![Test Coverage](https://camo.githubusercontent.com/77e60b770bfbe842e0ac26bdd98deb80bddb8b0a4907124609ed3fb698a57a6c/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4d65746153796e746163746963616c2f676f6f676c652d646972656374696f6e732d636c69656e742f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/MetaSyntactical/google-directions-client/coverage)[![SensioLabsInsight](https://camo.githubusercontent.com/b0dc12baa86fe5ec2d3b0ef1dbe6f39b3a806f484fed03a1353ebc6efc9c6dff/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f38373461303236352d386537392d346465642d393436622d6636333838643362363163372e7376673f7374796c653d666c6174266c6162656c3d696e7369676874)](https://insight.sensiolabs.com/projects/874a0265-8e79-4ded-946b-f6388d3b61c7)

What is MetaSyntactical/GoogleDirections?
-----------------------------------------

[](#what-is-metasyntacticalgoogledirections)

MetaSyntactical/GoogleDirections is a PHP client library for the [Google Maps Directions API](https://developers.google.com/maps/documentation/directions). Its purpose is to calculate a route between given geographical coordinates.

Prerequisites for using the Google Directions API
-------------------------------------------------

[](#prerequisites-for-using-the-google-directions-api)

To use this library you will need a Google API key which can be obtained from Google. Usage of the Google API is subject to Terms and Conditions set out by Google. Depending on the way of you want to use Google's API and the amount of traffic/requests Google may charge fees. Please refer to [Google Maps Directions API](https://developers.google.com/maps/documentation/directions)for further details.

Installation
------------

[](#installation)

The easiest way to install the library is adding it as a dependency to your project's composer.json file.

```
$ composer require metasyntactical/google-directions-client "^2"

```

If you use PHP version 5.5.x, 5.6.x or 7.0.x you can revert to an earlier compatible version of the library:

```
$ composer require metasyntactical/google-directions-client "^1"

```

Usage
-----

[](#usage)

To use the library create an instance of the client class:

```
use MetaSyntactical\GoogleDirections\Client as GoogleApiClient;
use MetaSyntactical\GoogleDirections\Polyline as Polyline;
use MetaSyntactical\GoogleDirections\RouteFactory;
use GuzzleHttp\Client as HttpClient;
use MetaSyntactical\Http\Transport\Guzzle\GuzzleTransport;

$guzzleTransport = new GuzzleTransport(new HttpClient());

$polylineDecoder = new Polyline();

$googleApiClient = new GoogleApiClient(
    'string', // setLogger($logger);
$polylineDecoder->setLogger($logger);

```

The client uses a Route object as a value object to handle the geographical coordinates. The easiest way to obtain a route object is via the factory, which will take an array of comma-separated coordinates (lat,long) for which you want to calculate a route:

```
$coordinates = array(
    '50.1109756,8.6824697',
    '50.1131057,8.6935646',
    '50.1114651,8.704576',
    '50.1128467,8.7049644'
);
$routeFactory = new RouteFactory();
$route = $routeFactory->createRoute($coordinates);

```

Note that the order of coordinates is relevant, meaning the route will start at the first given coordinate and pass through any additional coordinate in the given order up to the last given coordinate.

As with the Polyline object, you can pass a PSR-3 logger to the route factory to collect messages:

```
$routeFactory->setLogger($logger);

```

To get an interpolated route call the getDirections() method of the Google API client and pass the route object as an argument:

```
$resultRoute = $googleApiClient->getDirections($route);

```

The return value will be a Route object. Depending on the size of the route (number of coordinates), one API call (i.e. one call of the getDirections() method will only yield a partial result. This is due to the fact that the Google API handles only a limited number of waypoints per request.

You can check if there are coordinates left in the route for which additional calls to the Google API need to be made. In order to do so use the getRemainingCoordinateCount() method.

```
$resultRoute->getRemainingCoordinateCount();

```

If the count is greater than zero, just call the getDirections() method again with the result route as an argument and the Google API is called again yielding another portion of the route:

```
$resultRoute = $googleApiClient->getDirections($route);

```

Once there are no more remaining coordinates, all coordinates that make up the interpolated route can be retrieved by calling the getInterpolatedRoute() method on the result route object.

```
$resultRoute->getInterpolatedRoute();

```

Note that the getInterpolatedRoute() method returns an array of Coordinate objects, that have methods to get the values for latitude and longitude:

```
$coordinate->getLatitude();
$coordinate->getLongitude();

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~215 days

Total

5

Last Release

2900d ago

Major Versions

v1.0.3 → v2.0.02018-06-02

PHP version history (2 changes)v1.0PHP &gt;=5.5.0

v2.0.0PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/59dfdaddf6da9851c4af1ef88da592dc5386554d2ea441806f3d926786b6d01b?d=identicon)[dkreuer](/maintainers/dkreuer)

![](https://www.gravatar.com/avatar/1035635fd872a1c350cf3d367b92eeef638be049ed83a8a2dcf684d63074bcd2?d=identicon)[dweichert](/maintainers/dweichert)

---

Top Contributors

[![dweichert](https://avatars.githubusercontent.com/u/2235895?v=4)](https://github.com/dweichert "dweichert (51 commits)")

---

Tags

clientroutinggeographyGoogle Maps Directions API

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/metasyntactical-google-directions-client/health.svg)

```
[![Health](https://phpackages.com/badges/metasyntactical-google-directions-client/health.svg)](https://phpackages.com/packages/metasyntactical-google-directions-client)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69333.0M114](/packages/algolia-algoliasearch-client-php)[resend/resend-php

Resend PHP library.

564.7M21](/packages/resend-resend-php)[crowdin/crowdin-api-client

PHP client library for Crowdin API v2

611.5M5](/packages/crowdin-crowdin-api-client)[mozex/anthropic-laravel

Anthropic PHP for Laravel is a supercharged PHP API client that allows you to interact with the Anthropic API

71226.4k1](/packages/mozex-anthropic-laravel)[markrogoyski/numverify-api-client-php

Numverify API Client for PHP

1220.9k](/packages/markrogoyski-numverify-api-client-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
