2017 © Pedro Peláez
 

library distancematrix

API wrapper to get the distance between two addresses using Google's Distance Matrix API

image

martijnoud/distancematrix

API wrapper to get the distance between two addresses using Google's Distance Matrix API

  • Wednesday, February 8, 2017
  • by MartijnOud
  • Repository
  • 2 Watchers
  • 4 Stars
  • 60 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 3 Versions
  • 43 % Grown

The README.md

DistanceMatrix PHP API Wrapper

Very simple API Wrapper for Google's DistanceMatrix API. Enter two addresses and the class returns the distance between them in meter. Alternatively use Google Static Map API to generate a map with a line plotted between two adresses., (*1)

Install

Install using composer:, (*2)

$ composer require martijnoud/distancematrix

Basic usage

Calculate the distance in meters between the Inktweb.nl office and Paleis Noordeinde in the Hague., (*3)

use MartijnOud\DistanceMatrix\DistanceMatrix;

$distanceMatrix = new DistanceMatrix(YOUR_API_KEY_HERE);

$distance = $distanceMatrix->distance([
    'origins' => 'Prof. van der Waalsstraat 2 Alkmaar', 
    'destinations' => 'Paleis Noordeinde Den Haag'
]);

if ($distance > 0) {
    echo round($distance / 1000, 2) . "km"; // 84.5km
}

More control

use MartijnOud\DistanceMatrix\DistanceMatrix;

$distanceMatrix = new DistanceMatrix(YOUR_API_KEY_HERE);

$distance = $distanceMatrix->distance([
    'origins' => 'Leith', 
    'destinations' => 'Arques',
    'mode' => 'walking',
    'language' => 'en-GB',
]);

if ($distance > 0) {
    echo "I would walk " . $distance * 0.00062137119 . " miles"; // I would walk 493.88322020532 miles
}
````

## Generating a map
An API key is not required for this. If you do supply a key make sure this key has premission to use the Static Map API.
```php
use MartijnOud\DistanceMatrix\DistanceMatrix;

$distanceMatrix = new DistanceMatrix();

$image = $distanceMatrix->map([
    'origins' => 'Prof. van der Waalsstraat 2 Alkmaar', // required
    'destinations' => 'Amsterdam', // required
    'size' => '728x200'
]);

if ($image) {
    echo '<img src="'.$image.'" />';
}

google-static-map, (*4)

Todo

Ideas for future versions., (*5)

  • [ ] Better error handling, checking rate limit, etc
  • [x] Show a map with a line plotted between two points

The Versions

08/02 2017

dev-master

9999999-dev

API wrapper to get the distance between two addresses using Google's Distance Matrix API

  Sources   Download

MIT

by Martijn Oud

08/02 2017

v1.2.0

1.2.0.0

API wrapper to get the distance between two addresses using Google's Distance Matrix API

  Sources   Download

MIT

by Martijn Oud

22/06 2015

dev-dev

dev-dev

API wrapper to get the distance between two addresses using Google's Distance Matrix API

  Sources   Download

MIT

by Martijn Oud