Drupal Geocoder PHP module

This module is a Drupal wrapper/implementation for the Geocoder PHP library: "The most featured Geocoder library written in PHP, which helps you build geo-aware applications by providing a powerful abstraction layer for geocoding manipulations".

It is commonly used to automatically Geocode string/text Point addresses and WKT Geometries into Geofield, as well as to Reverse Geocode Geofield Points into String/Text Point addresses, and other Geocoder PHP library formats.

Features

  • Solid API based on the Geocoder PHP library (supporting both v4 and v5, compatible with PHP 8.4+);
  • Geocode and Reverse Geocode using one or multiple Geocoder Providers (ArcGISOnline, BingMaps, File, GoogleMaps, Nominatim, OpenStreetMap, and many more);
  • Results can be output into multiple formats such as WKT, GeoJson, etc.;
  • The Geocoder Provider and Dumper plugins are extendable through a custom module;
  • Geocoder Providers are managed as Config Entities, allowing full configuration management and export/import via CMI;
  • Submodule Geocoder Field provides Drupal fields widgets and formatters, with advanced geocoding/reverse-geocoding options on entity fields;
  • Geofield and Address field integration;
  • Core Image and File modules integration (for Geo-Tagged images and uploaded KML, GeoJSON, GPX files) into Drupal Geofield format;
  • Caching of geocoding results, enabled by default;
  • Queue-based geocoding: option to process Geocode operations asynchronously via Drupal's Queue API, to handle large-scale entity updates or migrations efficiently;
  • Ability to intentionally skip geocoding on specific entity saves (e.g. during migrations or bulk workspace publishing), to avoid unnecessary API calls or failure messages;
  • Support for passing additional parameters to geocoding providers for fine-grained control;
  • Developer hook hook_geocoder_address_values_alter() to alter address values before geocoding takes place;
  • Full Drupal 9, 10, and 11 compatibility (Guzzle 7, PSR-18 HTTP client compliant);
  • GitLab CI integration (composer-lint, PHPCS, PHPStan, ESLint, StyleLint, PHPUnit);

Included Submodules

The following submodules are bundled with the Geocoder package and provide extended integration capabilities:

  • Geocoder Field (geocoder_field): Adds the ability to configure Geocode and Reverse Geocode operations on Entity fields (on insert/edit) and as field Geo formatters, leveraging all available Geocoder Provider Plugins and output formats (via Dumpers);
  • Geocoder Geofield (geocoder_geofield): Provides integration with the Geofield module/field type — use it as the target of Geocode operations or as the source for Reverse Geocoding;
  • Geocoder Address (geocoder_address): Provides integration with the Address module/field type — use it as the target of Reverse Geocode operations or as the source for Geocoding;

Compatible and Recommended Modules

  • Geofield module (recommended location storage);
  • Geolocation (alternative location storage);
  • Address module;
  • Core Image and File modules (for Geo-Tagged and uploaded KML, GeoJSON, GPX files);
  • Geocoder autocomplete — provides a nice autocomplete text widget;

Geocoder 1.x (Drupal 7 — unsupported | end of life)

Features

  • Geocode Address or location data from any text or Addressfield value (using Google, Yahoo, Yandex, or MapQuest).
  • Read Geotags from EXIF data in your photos.
  • Convert any GPX Tracklog into a Linestring.
  • Convert uploaded KML files into geometries.
  • Convert uploaded or typed GeoJSON and WKT into geometries.
  • Services module integration. You can easily transform Drupal into a general purpose geocoding server using REST, SOAP, XMLRPC etc.

Requirements for D7

All you need to do is install the geoPHP module, which is required by geocoder.

There's a nice video tutorial on using geocoder, addressfield, and geofield here.

Find detailed documentation in the README.md file.


Geocoder 2.x (Drupal 8 — unsupported)

This is a complete rewrite of the Geocoder module, based on the Geocoder PHP libraryVersion 3.x.


Geocoder 3.x (Drupal 8/9 — unsupported)

This is an evolution of the Geocoder 2.x module (deprecated), based on the Geocoder PHP library — Version 4.x.
Starting with this version the Geocoder providers are config entities, whereas in earlier versions the provider settings were stored in simple configuration. An upgrade path is provided but any code that was relying on the old simple config will need to be updated to use the config entities instead.
An upgrade path is provided but any code that was relying on the 2.x simple config will need to be updated to use the config entities instead.

Installation of the Geocoder 8.x-3.x version for D8/D9

  1. Download the module by requiring it via Composer. This will also download the Geocoder PHP library as willdurand/geocoder.
  2. Enable the module (and its sub-modules) via Drush.
  3. Choose the Geocoder Provider you want to use and also add it as a required dependency to your project. For example if you want to use Google Maps as your provider:
    $ composer require geocoder-php/google-maps-provider
    (You will find it as a possible geocoder provider choice in the "add provider" options on the Geocoder module settings page at /admin/config/system/geocoder.)

Upgrading from Geocoder 2.x to 3.x

When upgrading to the new Geocoder 8.x-3.x branch you would need to:

  • Remove the Geocoder 8.x-2.x branch first ($ composer remove drupal/geocoder), and make sure its dependency willdurand/geocoder: "^3.0" library is also removed.
  • Require the new default Geocoder 3.x version ($ composer require drupal/geocoder).
  • Choose the Geocoder Provider you want to use and add it as a required dependency.
  • Run the database updates, either by visiting update.php or running $ drush updb.
  • Set back (update) the Geocoding & Reverse Geocoding settings for each field you previously applied them to.

Further detailed documentation and APIs are provided in the Geocoder 3.x README.md file.


Geocoder 4.x (Drupal 9, 10, 11)

This is the current stable and recommended branch. It is a parallel evolution of the Geocoder 3.x branch, requiring php-http/guzzle7-adapter and therefore compatible with Guzzle 7 (a requirement for Drupal 10+). It also supports the willdurand/geocoder v5 library, which introduces PHP 8.4 compatibility and a range of upstream bug fixes.

Further detailed documentation and APIs are provided in the Geocoder 4.x README.md file.

How to seamlessly upgrade to Drupal 10 & Geocoder 4.x

When preparing for an upgrade to Drupal 10 we recommend that you widen your Composer version constraints to allow either 3.x or 4.x.
Edit composer.json the following way:

  "require": {
  ...
  "drupal/geocoder": "^3.20 || ^4.0",
  ...
  }

This will allow the module to be automatically upgraded when you upgrade Drupal core (refer to this Issue comment for more info).

Project information

Releases