cirovargas/google-distance-matrix

Google 距离矩阵 API - 估算多个起点和终点的旅行时间和距离。

v0.0.10 2021-04-13 21:13 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:06:00 UTC


README

为多个目的地估算旅行时间和距离。

需求

需要 PHP 7.0 或更高版本。

安装

安装 cirovargas/google-distance-matrix 的最佳方式是使用 Composer

$ composer require cirovargas/google-distance-matrix

入门

$distanceMatrix = new GoogleDistanceMatrix('YOUR API KEY');
$distance = $distanceMatrix->setLanguage('cs')
    ->addOrigin('49.950096, 14.668544')
    ->addOrigin('49.950096, 15.668544')
    ->addDestination('50.031817, 14.490880')
    ->addDestination('51.031817, 14.490880')
    ->sendRequest();
$distanceMatrix = new GoogleDistanceMatrix('YOUR API KEY');
$distance = $distanceMatrix
    ->setOrigin('K Habrovci 447, 251 63 Strančice, Česká republika')
    ->setDestination('Roztylská 2321/19, Chodov, 148 00 Praha-Praha 11, Česká republika')
    ->setMode(GoogleDistanceMatrix::MODE_WALKING)
    ->setLanguage('en-US')
    ->setUnits(GoogleDistanceMatrix::UNITS_IMPERIAL)
    ->setAvoid(GoogleDistanceMatrix::AVOID_HIGHWAYS)
    ->sendRequest();

更多信息,请访问 https://developers.google.com/maps/documentation/distance-matrix/