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, so as Reverse Geocode Geofield Points into String/Text Point addresses, and other Geocoder PHP library formats.
In its Geocoder 1.x for Drupal 7 version, it also supports the Geolocation and Location modules for converting Points.
This module makes available an API to convert the information you already have into geographic information. It support a variety of input formats and runs them through pluggable backends to produce geographic information.
In addition to Latitude / Longitude points, this API also supports more complex geographies such as lines and polygons.
Compatible modules
- Geofield (recommended location storage);
- Core String and Text fields, Addressfield and Address for D8/D9 (recommended address storage);
- Core Image and File modules (for Geo-Tagged and uploaded KML, Geojson, GPX files), into Drupal Geofield Format;
- location (alternative location or address storage, only for D7 version);
- geolocation (alternative location storage, only for D7 version);
- geocoder-autocomplete Provides a nice auto-complete text-widget. (Doesn't use geocoder api);
- Computed Field;
Geocoder 1.x (Drupal 7)
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.
Tutorial
There's a nice video tutorial on using geocoder, addressfield, and geofield here
APIs
In addition to the GUI-based widget, geocoder also provides a nice general API for doing geocoding. Here's an example:
out('json');
// List all available handlers
$handlers = geocoder_handler_info();
dpm($handlers);
?>
New geocoder handlers are easy to define. Simply create a new ctools plugin of the type "geocoder_handler".
Find detailed documentation in the README.md file.
Geocoder 2.x (Drupal 8)
This is a complete rewrite of the Geocoder module, based on the Geocoder PHP library - Version 3.x.
Features
- Solid API based on Geocoder PHP library
- Geocode and Reverse Geocode using one or multiple Geocoder providers (ArcGISOnline, BingMaps, File, GoogleMaps, Nominatim, OpeneStreetMap, etc);
- Results can be dumped into multiple formats such as WKT, GeoJson, etc ...
- The Geocoder Provider and Dumper plugins are extendable through a custom module;
- Submodule Geocoder Field provides Drupal fields widgets and formatters, with even more options;
- Geofield and Address field integration;
- Caching results capabilities, enabled by default;
Requirements for D8/D9
Installation for D8/D9
- Download the module running the following shell command from you project root (at the composer.json file level):
$ composer require "drupal/geocoder"
Note: this will also download the Geocoder PHP library as vendor/willdurand/geocoder
- Enable the module via Drush
$ drush en geocoder
or the website back-end/administration interface;
- Eventually enable also the submodules: geocoder_field, geocoder_geofield, geocoder_address;
Detailed Documentation and APIs
Find detailed documentation, also on its APIs in the README.md file.
Geocoder 3.x (Drupal 8/9)
This is an evolution of the Geocoder 2.x module, 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 the Geocoder 8.x-3.x version for D8/D9
- Download the module running the following shell command from you project root (at the composer.json file level):
$ composer require "drupal/geocoder:^3.0@beta"
Note: this will also download the Geocoder PHP library as willdurand/geocoder": "^4.0" library
- Enable the module (and its sub-modules) via Drush
- 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 that as a possible geocoder provider choice in the "add provider"
options of the Geocoder module settings page ('/admin/config/system/geocoder')
Upgrading from Geocoder 2.x to 3.x
Geocoder 3.x is not back compatible with Geocoder 2.x and no upgrade path has been provided so for general and fields configurations settings.
At the moment, upgrading to Geocoder 3.x requires a complete uninstall and removal of Geocoder 2.x with the following steps:
- Uninstall Geocoder 2.x, via Drupal backend or with `drush pmu geocoder`
- Remove Geocoder 2.x via composer: `composer require drupal/geocoder`
- Make sure also its dependency willdurand/geocoder": "^3.0" library is removed
Further Detailed Documentation and APIs provided in the Geocoder 3.x Readme.md file.