juststeveking/laravel-city-mapper

A service wrapper around the City Mapper API

v1.1 2020-01-16 16:33 UTC

This package is auto-updated.

Last update: 2020-02-16 16:48:47 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

A service wrapper around City Mapper

Install

Via Composer

$ composer require juststeveking/laravel-city-mapper

After installation, merge configuration for services uusing:

$ php artisan vendor:publish --provider="JustSteveKing\LaravelCityMapper\CityMapperServiceProvider"

If, for some reason, this doesn't work please use the following steps:

  • Add the following into the config/services.php configuration file:
<?php

'citymapper' => [
    'key' => env('CITY_MAPPER_KEY', '')
]
  • Add CITY_MAPPER_KEY to your .env file and add your API key which you can get from here.

Basic Usage

If you want to interact with the service itself

<?php 

class SomeController extends Controller
{
    protected $cityMapper;

    public function __construct(CityMapperService $service)
    {
        $this->cityMapper = $service;
    }

    public function index(Request $request)
    {
        // get the travel time between two points
        $startCoordinates = [
            51.525246, // latitude
            0.084672 // longitude
        ];
        
        $endCoordinates = [
            51.559098, // latitude
            0.074503 // longitude
        ];
    
        $travelTime = $this->cityMapper->getTransitTime(
            $startCoordinates,
            $endCoordinates
        );
    }
}

This will return the following stdClass object:

.{#330
  +"travel_time_minutes": 43
}

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email juststevemcd@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.