Download the PHP package metasyntactical/google-directions-client without Composer

On this page you can find all versions of the php package metasyntactical/google-directions-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package google-directions-client

README

Build Status Downloads this Month Latest stable Latest dev License Code Climate Test Coverage SensioLabsInsight

What is MetaSyntactical/GoogleDirections?

MetaSyntactical/GoogleDirections is a PHP client library for the Google Maps Directions API. Its purpose is to calculate a route between given geographical coordinates.

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 for further details.

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

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

The client class has a few dependencies that must be passed to the constructor:

You can optionally set a logger on both the Google API Client object and the Polyline object to collect messages. The logger object you pass must implement the PSR-3 logger interface.

$googleApiClient->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:

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:


All versions of google-directions-client with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
psr/log Version ^1.0
beberlei/assert Version ^2.9
metasyntactical/http-transport-guzzle Version ^1.1
guzzlehttp/guzzle Version ^6.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package metasyntactical/google-directions-client contains the following files

Loading the files please wait ....