定制 wubs/simple-google-directions-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wubs/simple-google-directions-api

最新稳定版本:0.1.14

Composer 安装命令:

composer require wubs/simple-google-directions-api

包简介

Communicates with the google directions api

README 文档

README

This is a simple laravel package to get basic information from the Google Directions API.

Installation

To install this library into your project simply do the following in your project root:

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.

Usage

You can use the facade like this:

<?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:

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

Or inject it into a constructor

<?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:

php artisan vendor:publish

Afterwards the configuration will be located in config/directions.php

I highly recommend using the .env file.

Non laravel usage

The package is also usable without Laravel. See the code below.

<?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);

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-04-28