Using Address module with Geocoder and Geofield
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).
- 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 - Install a provider, for example Nominatim (used by OpenStreetMap):
composer require geocoder-php/nominatim-provider - Create a "Nominatim" Geocoder provider under /admin/config/system/geocoder/geocoder-provider:
- Root URL: https://nominatim.openstreetmap.org
- User Agent: Value of the User-Agent header, for example "Drupal example.org". Replace "example.org" with your URL.
- Referer: Value of the Referer header, for example "https://example.org". Replace with your URL.
- Create an Address field called "Location" in a content type, to supply an address
- Create a Geofield field called "Map" in a content type, allowing only one value
- 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"
- 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
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.