navjobs/google-geocoder

此包已被废弃且不再维护。未建议替代包。

通过Google Maps进行地理编码的抽象。

0.2.1 2019-02-20 19:26 UTC

This package is not auto-updated.

Last update: 2022-05-23 23:39:35 UTC


README

Circle CI Code Climate

Google Geocoding

提供对Google Maps地理编码服务的请求的抽象。

安装

您可以使用以下命令通过Composer安装此包:

composer require ConstructionJobs/google-geocoder

Laravel安装

此包包含一个服务提供者,可用于Laravel。如果您使用的是Laravel 5.5及以上版本,则无需进行任何操作。

如果您使用的是Laravel 5.4或以下版本,则安装服务提供者的方法如下:

// config/app.php
'providers' => [
    // other providers
    'ConstructionJobs\GoogleGeocoder\GoogleGeocoderServiceProvider'
];

您还必须发布配置文件

php artisan vendor:publish --provider="ConstructionJobs\GoogleGeocoder\GoogleGeocoderServiceProvider"

配置文件允许您设置您的API密钥语言区域

用法

您可以使用三种方式使用此包。

// Geocode an address
$geocoder = new Geocoder;
$geocoder->geocode('New York, NY');

// Reverse geocode from coordinates
$geocoder = new Geocoder;
$geocoder->reverseByCoordinates(40.7127837, -74.0059413);

// Reverse geocode from a Google place id.
$geocoder = new Geocoder;
$geocoder->reverseByPlaceId('ChIJOwg_06VPwokRYv534QaPC8g');

所有这些方法都返回以下标准响应格式:

[
    'address' => 'New York, NY, USA',
    'latitude' => 40.7127837,
    'longitude' => -74.0059413,
    'place_id' => ChIJOwg_06VPwokRYv534QaPC8g,
    'types' => [
        'locality',
        'political'
    ]
    $bounds = [
        'northeast' => [
            'latitude' => 40.9152555,
            'longitude' => -73.7002721,
        ],
        'southwest' => [
            'latitude' => 40.496044,
            'longitude' => -74.255735,
        ]
    ];
}