markuskooche/geocode

此包已被废弃,不再维护。作者建议使用 geocoder-php/common-http 包代替。

一个用于(反向)地理编码的简单封装。

v0.3-beta 2023-05-03 14:03 UTC

This package is auto-updated.

Last update: 2024-03-21 22:23:49 UTC


README

安装

composer require markuskooche/geocode

使用

如何进行地理编码

use Illuminate\Support\Collection;
use Markuskooche\Geocode\Geocode;

// Get the longitude and latitude of a location.
$street = 'Pennsylvania Avenue Northwest';
$number = '1917';
$city = 'Washington';
$zip = '20500';
      
// You only need api key for the google maps driver.
// The standard driver will use the openstreet maps api.  
$geocode = new Geocode(<driver_instance>);
$coordinates = $geocode->coordinates($street, $number, $city, $zip);
/**
 * The coordinates is returned as a collection.
 * @var Collection $coordinates
 */
$coordinates = [
    'longitude' => '-77.037852'
    'latitude'  => '38.898556',
];

如何进行反向地理编码

use Illuminate\Support\Collection;
use Markuskooche\Geocode\Geocode;

// Get the street, number, city and zip of a location.
$longitude = -77.0442641;
$latitude = 38.9004915;

// You only need api key for the google maps driver.
// The standard driver will use the openstreet maps api.
$geocode = new Geocode(<driver_instance>);
$address = $geocode->address($longitude, $latitude);
/**
 * The address is returned as a collection.
 * @var Collection $address
 */
$address = [
    'street' => 'Pennsylvania Avenue Northwest',
    'number' => '1917',
    'city'   => 'Washington',
    'zip'    => '20500',
];

导出配置

php artisan vendor:publish --provider="Markuskooche\Geocode\GeocodeServiceProvider" --tag="config"

许可证

Geocode 是一个开源软件,根据 MIT 许可证 许可。