定制 bogdaan/distance 二次开发

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

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

bogdaan/distance

Composer 安装命令:

composer require bogdaan/distance

包简介

Geo distance library for PHP.

README 文档

README

Build Status

This library provide:

  • distance calculation
  • distance matrix calculation

Note that the library does not provide geocoding features (for these purposes, you can use this library).

Example

use Distance\Model\Distance;
use Distance\Model\Coordinate;
use Distance\Exception\PoolError;

// for HTTP providers
$client = new GuzzleHttp\Client();

// fail-safe distance source
$pool = new Distance\ProviderPool([

    // Google distance matrix provider
    new Distance\Provider\GoogleProvider($client),

    // OSRM server with distance_table plugin
    new Distance\Provider\OsrmProvider($client, [
        'baseUrl' => 'http://localhost:2233/',
    ]),

    // graphhopper service
    new Distance\Provider\GraphhopperProvider($client,[
        'key' => 'YOU_API_KEY'
    ]),

    // routexl.com distance matrix
    new Distance\Provider\RoutexlProvider($client, [
        'username' => 'YOU_API_USERNAME',
        'password' => 'YOU_API_PASSWORD',
    ]),

    // optinal (If all previous fails) - math provider
    new Distance\Provider\HaversinaProvider(),
]);

// GPS coordinates
$coords = [
    new Coordinate(48.41, 34.81),
    new Coordinate(48.43, 35.22),
    new Coordinate(48.43, 36.22).
];

// case1: single distance
$distanceObject = $pool->getDistance($coords[0], $coords[1]);
$distanceInMeters = $distanceObject->getDistance(Distance::UNIT_METER);
$distanceInMiles = $distanceObject->getDistance(Distance::UNIT_MILE);


// case2: distance matrix 3x3
$matrix = $pool->getDistanceMatrix($coords);
$distanceInMeters = $matrix->getDistance($coords[0], $coords[1], Distance::UNIT_METER);

Instalation

Using composer:

$ composer require bogdaan/distance

Providers

Currently supported providers:

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-20