iseed838/graphhopper-api

graphhopper-api 项目包装器

0.2.5 2021-11-23 04:59 UTC

This package is auto-updated.

Last update: 2024-09-23 11:21:43 UTC


README

Graphhopper 是一个强大的方向API,用于规划您的应用程序 graphhopper

此项目是一个包装器,用于向方向API发送API请求

可以使用以下命令安装包装器

  • composer require "iseed838/graphhopper-api" "~0.2"

目前有2种服务绑定

  • 路由API
  • 地理编码API
  1. 制作路由请求
$pathRequest = new \Graphhopper\Models\RouteRequest([
    'points'   => [
        '55.630358,37.516776',
        '55.6916244,37.7225474'
    ],
]);

$client = new \Graphhopper\Models\Clients\RouteClient(new \GuzzleHttp\Client(), [
    'key'                => '123-asd',
]);
$pathResponse = $client->paths($pathRequest);

将得到响应

Graphhopper\Models\RouteResponse Object
(
    [info:Graphhopper\Models\RouteResponse:private] => Array
        (
            [copyrights] => Array
                (
                    [0] => GraphHopper
                    [1] => OpenStreetMap contributors
                )

            [took] => 2
        )

    [paths:Graphhopper\Models\RouteResponse:private] => Array
        (
            [0] => Array
                (
                    [distance] => 20048.589
                    [weight] => 1276.548563
                    [time] => 1276419
                    [transfers] => 0
                    [snapped_waypoints] => wiprIik~cFi|Jyjg@
                    [points] => [
                        [type] => LineString
                        [coordinates] => [
                            [
                                [0] => 37.516213
                                [1] => 55.630528
                            ],
                            [
                                    [0] => 37.515701
                                    [1] => 55.629986
                            ]
                        ]   
                    ],
                    [legs] => [
                    
                    ],
                    [details] => [
                        [distance] => [
                            [
                                [0] => 0
                                [1] => 1
                                [2] => 68.227871223281
                            ],
                            [
                                [0] => 1
                                [1] => 2
                                [2] => 32.217
                            ],
                        ]
                    ]                   
                )

        )

    [hints:Graphhopper\Models\RouteResponse:private] => Array
        (
            [visited_nodes.average] => 268.0
            [visited_nodes.sum] => 268
        )

)
  1. 制作地理编码请求
  • 查询请求
$queryGeocodeRequest = new \Graphhopper\Models\GeocodeQueryRequest([
    'query' => 'Moscow Vavilova 6',
    'language' => \Graphhopper\Factory::LANGUAGE_EN
]);

$client = new \Graphhopper\Models\Clients\GeocodeClient(new \GuzzleHttp\Client(), [
    'key'                => '123-asd',
]);
$geocodeResponse = $client->query($queryGeocodeRequest);
  • 反向请求
$reverseGeocodeRequest = new \Graphhopper\Models\GeocodeReverseRequest([
    'point' => '55.630358,37.516776',
    'language' => \Graphhopper\Factory::LANGUAGE_RU
]);

$client = new \Graphhopper\Models\Clients\GeocodeClient(new \GuzzleHttp\Client(), [
    'key'                => '123-123',
]);
$geocodeReverseResponse = $client->reverse($reverseGeocodeRequest);

将返回

Graphhopper\Models\GeocodeResponse Object
(
    [took:Graphhopper\Models\GeocodeResponse:private] => 1470
    [copyrights:Graphhopper\Models\GeocodeResponse:private] => Array
        (
        )

    [hits:Graphhopper\Models\GeocodeResponse:private] => Array
        (
            [0] => Array
                (
                    [osm_id] => 5607914901
                    [osm_type] => N
                    [country] => India
                    [osm_key] => place
                    [city] => Thiruvanchoor
                    [osm_value] => locality
                    [postcode] => 686010
                    [name] => Moscow Junction
                    [state] => Kerala
                    [point] => Array
                        (
                            [lng] => 76.560045
                            [lat] => 9.613103
                        )

                )
        )

    [locale:Graphhopper\Models\GeocodeResponse:private] =>
)

路由请求模型具有以下参数

  • points (必需|string[]|count>1) - 点坐标
  • vehicle (必需|string) - 车辆类型。可用car,foot,bike,默认car;
  • language (必需|string) - 请求语言。可用en,ru,de,fr,it。默认en;
  • is_calc_points (字符串) - 是否需要计算点。默认false;
  • limit (必需|整数) - 响应变体的数量
  • is_instructions (字符串) - 是否需要路径的文本说明。默认false;
  • is_point_encoded (字符串) - 是否需要点编码的点。默认false;
  • details (字符串[]) - 响应详细。可用'distance', 'time', 'weight', 'line'。默认'distance';

地理编码查询请求模型具有以下参数

  • query (必需|string) - 地址字符串;
  • point (字符串) - 点坐标;
  • language (必需|string) - 请求语言。可用en,ru,de,fr,it。默认en;
  • provider (必需|string) - 查询提供商。可用'default', 'nominatim'。默认'default'
  • limit (必需|整数) - 响应变体的数量。默认5;

地理编码反向请求模型具有以下参数

  • point (必需|string) - 点坐标;
  • language (必需|string) - 请求语言。可用en,ru,de,fr,it。默认en;
  • provider (必需|string) - 查询提供商。可用'default', 'nominatim'。默认'default';
  • limit (必需|整数) - 响应变体的数量。默认1;