2017 © Pedro Peláez
 

library simple-google-directions-api

Communicates with the google directions api

image

wubs/simple-google-directions-api

Communicates with the google directions api

  • Thursday, April 30, 2015
  • by megawubs
  • Repository
  • 1 Watchers
  • 2 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Simple Goolge Directions API

This is a simple laravel package to get basic information from the Google Directions API., (*1)

Installation

To install this library into your project simply do the following in your project root:, (*2)

composer require wubs/simple-google-directions-api:0.*

Laravel specific

If you use Laravel, add 'Wubs\Directions\DirectionsServiceProvider', to app/config.php in the providers array and add 'Directions' => 'Wubs\Directions\Facades\Directions', to the aliases array, also in app/config.php., (*3)

Usage

You can use the facade like this:, (*4)

<?php
$options = new DirectionOptions(
            DirectionOption::origin($address1->latitude, $address1->longitude),
            DirectionOption::destination($address2->latitude, $address2->longitude),
            DirectionOption::mode(TravelModes::BICYCLING),
            DirectionOption::alternatives(true),
            DirectionOption::language("nl_NL"),
            DirectionOption::departureTime(Carbon::now())
        );
$routes = Directions::route($options);

Or get it from the IoC container like so:, (*5)

<?php
$api = $app->make('\Wubs\Directions\Directions')

Or inject it into a constructor, (*6)

<?php namespace App\Http\Controllers;

use Wubs\Directions\Directions;

class DirectionsController extends Controller
{
   private $api;

    public function __construct(Directions $directions)
    {
        $this->directions = $directions;

    }
}

Publish the configuration by running:, (*7)

php artisan vendor:publish

Afterwards the configuration will be located in config/directions.php, (*8)

I highly recommend using the .env file., (*9)

Non laravel usage

The package is also usable without Laravel. See the code below., (*10)

<?php
require 'vendor/autoload.php'

use Wubs\Directions\Directions;

$directions = new Directions(getenv("GOOGLE_DIRECTIONS_SERVER_KEY"));

$zipApi = new Wubs\Zip\ZipApi(getenv("ZIP_API_KEY"));
$address1 = $zipApi->address("8316PB", 28);
$address2 = $zipApi->address("6821HX", 1);

$options = new DirectionOptions(
    DirectionOption::origin($address1->latitude, $address1->longitude),
    DirectionOption::destination($address2->latitude, $address2->longitude),
    DirectionOption::mode(TravelModes::BICYCLING),
    DirectionOption::alternatives(true),
    DirectionOption::language("nl_NL"),
    DirectionOption::departureTime(Carbon::now())
);

$response = $directions->route($options);

The Versions

30/04 2015

dev-master

9999999-dev

Communicates with the google directions api

  Sources   Download

The Requires

 

The Development Requires

api wrapper google directions

30/04 2015

0.1.14

0.1.14.0

Communicates with the google directions api

  Sources   Download

The Requires

 

The Development Requires

api wrapper google directions

28/04 2015

0.1.13

0.1.13.0

Communicates with the google directions api

  Sources   Download

The Requires

 

The Development Requires

api wrapper google directions

28/04 2015

0.1.12

0.1.12.0

Communicates with the google directions api

  Sources   Download

The Requires

 

The Development Requires

api wrapper google directions

28/04 2015

0.1.11

0.1.11.0

Communicates with the google directions api

  Sources   Download

The Requires

 

The Development Requires

api wrapper google directions

28/04 2015

0.1.10

0.1.10.0

Communicates with the postcodeapi.nu api

  Sources   Download

The Requires

 

The Development Requires

api wrapper google directions

28/04 2015

0.0.01

0.0.01.0

Communicates with the postcodeapi.nu api

  Sources   Download

The Requires

 

The Development Requires

api wrapper google directions