puwnz/google-maps-bundle

将 Symfony 与 Google Maps 库捆绑使用

安装: 205

依赖者: 1

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 2

类型:symfony-bundle

1.3.0 2024-09-11 21:02 UTC

README

概览

Google Maps Lib 项目为您的 Symfony 4+ 和 PHP 7.3+ 项目提供 Google Map 库集成。目前,此库仅启用了地理编码,因为我的需求只在这一部分,但您可以打开 问题 来推动您的需求。

安装

要安装此库,您可以使用 composer

composer require puwnz/google-maps-bundle

集成

捆绑注册

<?php
// config/bundles.php

return [
    Puwnz\GoogleMapsBundle\GoogleMapsBundle::class => ['all' => true]
];

配置集成

您只需在应用程序中添加一个变量环境变量 GOOGLE_API_KEY 来设置配置。

默认配置

# config/packages/google_maps.yaml
google_maps:
    api_key: '%env(GOOGLE_API_KEY)%'

示例

要在您的 symfony 项目中使用此包,您可以按照以下示例进行

<?php

namespace App\Controller;

use Puwnz\GoogleMapsBundle\Service\GoogleService;
use Puwnz\GoogleMapsLib\Geocode\DTO\GeocodeResult;

class FooService  {

    /** @var GoogleService */
    private $googleService;

    public function __construct(GoogleService $geocodeService) {
        $this->googleService = $geocodeService;
    }
    
    /**
    * @return GeocodeResult[]
    */
    public function getGeocodeResult(string $address) : array
    {
        return $this->googleService->geocode($address);
    }
}

使用自定义缓存池

您可以为此库使用特定的缓存池。只需在您的缓存框架配置中添加一个新的池,如下所示

# config/packages/cache.yaml
framework:
  cache:
    pools:
      google_maps:
        adapter: 'cache.adapter.redis' # this example use redis

测试

该捆绑包由 PHPUnit 完全单元测试,代码覆盖率接近 100%

贡献

我们热爱贡献者!这是一个开源项目。如果您想贡献,请随意提出 PR!

许可证

Google Map Lib 使用 MIT 许可证。有关完整的版权和许可证信息,请阅读与源代码一起分发的 LICENSE 文件。