cowegis/contao-geocoder

Geocoder integration in Contao CMS

0.2.1 2020-12-08 14:51 UTC

This package is auto-updated.

Last update: 2024-04-17 14:36:26 UTC


README

Build Status Version License Downloads

This extension integrates the Geocoder PHP library into Contao CMS. It's designed for other extensions to use a common geocoder implementation.

Features

  • Geocoder service for other extensions
  • Out of the box support for nominatim and google maps
  • Extandable for other providers
  • Database driven configuration of providers in Contao backend
  • Application driven configuration of providers
  • API endpoint for geocode queries

Requirements

  • Contao ^4.4
  • PHP >= 7.1

Installation

Contao Manager

Search the cowegis/contao-geocoder package and install it.

Composer

 composer require cowegis/contao-geocoder ^0.2.0

Usage

Configuration

Optional application configuration

# 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"

Code example

<?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();
    }
}

License

This extension is licensed under LGPL-3.0-or-later