Using Address module with Geocoder and Geofield

Last updated on
24 March 2025

Here's how to set up Geofield and Geocoder to look up an address supplied via the Address module (optional), and show it with Leaflet (optional).

  1. Install Address, Geocoder, Geocoder Address, Geocoder Field, Geocoder Geofield, Geofield, and Leaflet (optional)
    Drush command:
    drush in address geocoder geofield geocoder_address geocoder_geofield geocoder_field leaflet
  2. Install a provider, for example Nominatim (used by OpenStreetMap):
    composer require geocoder-php/nominatim-provider
  3. Create a "Nominatim" Geocoder provider under /admin/config/system/geocoder/geocoder-provider:
  4. Create an Address field called "Location" in a content type, to supply an address
  5. Create a Geofield field called "Map" in a content type, allowing only one value
  6. Set up the Geofield field like this:
    • Geocode → Geocode from an existing field
    • Geocode from an existing field → select "Location [Address]"
    • Geocoder providers → check "Nominatim"
  7. For the Geofield field, in "Manage display" choose "Leaflet Map" (if available) or just "Raw Output"

To test if it works, create new content, filling out the Address field. After saving the node, the coordinates for the address should be looked up, and the Leaflet map should show the location on the map.

You might be able to get this to work without the Address module, it is not required.

GDPR compliance with openstreetmap.de

openstreetmap.org in Leaflet is hosted in Canada or USA, and uses Fastly.net as CDN. To respect GDPR, you can use openstreetmap.de by installing Leaflet More Maps. Under display settings for the "Map" field use "Leaflet Map" and under settings, set "Leaflet Map Tiles Layer" to "OpenStreetMap.de".

Nominatim installation fails

If installation of the Nominatim provider fails with a dependency conflict:

- nominatim-provider requires willdurand/geocoder:^4.0

... you can try:

ddev composer require geocoder-php/nominatim-provider -W

The -W flag (aka --with-all-dependencies) allows Composer to downgrade willdurand/geocoder to 4.6.0, which resolves all version constraints and works with PHP 8.3.

Help improve this page

Page status: No known problems

You can: