LaravelPackages.net
Acme Inc.
Toggle sidebar
tomoehlrich/taxifarefinder

A PHP/Laravel wrapper for the TaxiFareFinder API

8
0
1.0.1
About tomoehlrich/taxifarefinder

tomoehlrich/taxifarefinder is a Laravel package for a php/laravel wrapper for the taxifarefinder api. It currently has 0 GitHub stars and 8 downloads on Packagist (latest version 1.0.1). Install it with composer require tomoehlrich/taxifarefinder. Discover more Laravel packages by tomoehlrich or browse all Laravel packages to compare alternatives.

Last updated

TaxiFareFinder

This package can retrieve supported cities, taxi businesses and taxi fare information from the TaxiFareFinder API.

The TaxiFareFinder API key can be requested under https://www.taxifarefinder.com/contactus.php.

Installation

This package can be installed through composer.

composer require tomoehlrich/taxifarefinder

Laravel installation

This package can be used for Laravel and non-Laravel projects.

In Laravel 5.5+ the package will make use of the Laravel autoregister feature. In older versions of Laravel you have to manually install the package's service provider and facade.

// config/app.php
'providers' => [
    // ...
    TomOehlrich\TaxiFareFinder\TaxiFareFinderServiceProvider::class
];
// config/app.php
'aliases' => [
	// ...
	'TaxiFareFinder' => TomOehlrich\TaxiFareFinder\Facades\TaxiFareFinder::class,
]

Next, you have to publish the config file:

php artisan vendor:publish --provider="TomOehlrich\TaxiFareFinder\TaxiFareFinderServiceProvider"

The config file contains only one option. Please make sure that your API key is available here.

return [

    /*
    |--------------------------------------------------------------------------
    | TaxiFareFinder API Key
    |--------------------------------------------------------------------------
    |
    | The TaxiFareFinder API Key can be requested at
    | https://www.taxifarefinder.com/contactus.php
    |
    */

    'api_key' => env('TAXIFAREFINDER_API_KEY', ''),

];

Usage

First create a new instance of the TaxiFareFinder class.

$tff = new TaxiFareFinder('<YOUR API KEY>');

You can get the nearest city that is supported by the API:

return $tff->getNearestCity(1.290270, 103.851959);

/*
  This function returns the following array:

  Array
    (
        [name] => Singapore
        [full_name] => Singapore, Singapore
        [handle] => Singapore
        [locale] => zh_SG
        [distance] => 7747
    )

You can get details about a taxi fare.

return $tff->getTaxiFare(42.368025,-71.022155, 42.362571,-71.055543);

/*
  This function returns the following array:

  Array
    (
        [total_fare] => 20.61
        [initial_fare] => 2.6
        [metered_fare] => 10.42
        [tip_amount] => 2.69
        [tip_percentage] => 15
        [locale] => en_US
        [currency] => Array
            (
                [int_symbol] => USD
            )

        [rate_area] => Boston, MA
        [flat_rates] => Array
            (
            )

        [extra_charges] => Array
            (
                [0] => Array
                    (
                        [charge] => 2.25
                        [description] => Airport Fee
                    )

                [1] => Array
                    (
                        [charge] => 2.65
                        [description] => Harbor tunnel toll
                    )

            )

        [distance] => 4591.1
        [duration] => 544
    )

You can get a list of taxi companies in a city.

return $tff->getTaxiCompanies('Ho-Chi-Minh-Vietnam');

/*
  This function returns the following array:

  Array
    (
        [businesses] => Array
            (
                [0] => Array
                    (
                        [name] => DichungTaxi
                        [phone] => 093-607-0416
                        [type] => taxi
                    )

            )

    )

In Laravel you can just call

return TaxiFareFinder::getNearestCity(1.290270, 103.851959);

To catch exceptions you should wrap methods in a try .. catch block.

try {
    $fare = $tff->getTaxiFare(42.368025,-71.022155, 42.362571,-71.055543);
} catch(TomOehlrich\TaxiFareFinder\Exceptions\TffException $e) {
    return $e->getMessage();
} catch(\Exception $e) {
    return $e->getMessage();
}

This package comes with a couple of tests. Just enter your API key in tests/TestCase.php and run

composer test

Star History Chart