cowegis/contao-geocoder

Contao CMS中的地理编码器集成

安装: 51

依赖关系: 1

建议者: 1

安全: 0

星标: 1

关注者: 1

分支: 0

开放问题: 4

类型:contao-bundle

1.0.1 2024-09-17 09:20 UTC

README

Build Status Version License Downloads

此扩展将 Geocoder PHP库 集成到Contao CMS中。它旨在让其他扩展使用通用的地理编码器实现。

功能

  • 其他扩展的地理编码器服务
  • 内置对nominatimgoogle maps的支持
  • 可扩展以支持其他提供商
  • 在Contao后端数据库中驱动配置提供商
  • 应用驱动配置提供商
  • 地理编码查询的API端点

需求

  • Contao ^4.13 || ^5.3
  • PHP ^8.2

安装

 composer require cowegis/contao-geocoder ^1.0.0
 # Optional for Nominatim support
 composer require geocoder-php/nominatim-provider ^5.5
 # Optional for Google Maps support
 composer require geocoder-php/google-maps-provider ^4.6

使用

配置

可选的应用程序配置

# app/config/config.yml

cowegis_contao_geocoder:
    providers:
      foo:
        title: "Foo Geocoder"
        type: "google_maps"
        google_api_key: "ABC"
      bar:
        title: "Bar Geocoder"
        type: "nominatim"
    default_provider: "bar"

代码示例

<?php
 
use Cowegis\ContaoGeocoder\Provider\Geocoder;

final class MyService
{
    private $geocoder;
    
    public function __construct(Geocoder $geocoder)
    {
        $this->geocoder = $geocoder;
    }
    
    public function geocode(string $address) : \Geocoder\Location
    {
        return $this->geocoder
            // Optional use a specific geocoder. Otherwise the default provider is used 
            ->using('foo')
            ->geocodeQuery(\Geocoder\Query\GeocodeQuery::create($address))
            ->first();
    }
}

许可证

此扩展根据 LGPL-3.0-or-later 许可