This project is not covered by Drupal’s security advisory policy.
Countries, Regions, Districts (Counties) and Localities (City, Town, Village)
with coordinates and boundary polygons, synced from OpenStreetMap database.
This module creates geographic entities and imports information from OSM database manually via Batch GUI, and keeping them in sync via background Cron jobs, importing all last changes in synced OSM Elements by changed timestamp.
Module uses Overpass API queries with area search to find all objects inside Countries and subareas (Regions, Counties, Districts) boundaries - even localities, that didn't have filled tags with relation to any country or subarea!
By default it uses public Overpass API instance at http://overpass-api.de/api/interpreter that works very slow and unstable, have hard rate limits and sometimes shows 500 / 502 errors instead of result. So for stable work it's strongly recommended to use your own or more robust Overpass API instance (endpoint is configured at /admin/config/system/overpass-api url). Here is listed other public Overpass API instances, but it's not guaranteed that they will work better than default one.
Requirements
- Drupal 8 or higher.
- Applied patch from #2680571: Cannot reference an entity with a big int (size setting of ID field not propagated to reference field) to fix Drupal Core bug with BigInt id references (until it not fixed in core).
- Temporary: Node.js installed to run JavaScript converter of OSM element to GeoJSON (
assets/osm2geojson-lite/osm2geojson-lite). Now I'm rewriting it to pure PHP version. - Highly recommended installed PHP-GEOS extension for PHP. It is used to simplify OSM polygons of area boundaries to significantly decrease memory usage. Without it rendering of all countries on map will require more than 1Gb of PHP memory.
- If you use public instance of Overpass API - it works very slow and unstable, so increase the maximum execution time for PHP scripts to 300 seconds or more.
Dependencies
- Geofield module for store coordinates and boundary geometry.
- Leaflet module for display boundaries on map in UI.
- Overpass API module for querying data from OpenStreetMap database using Overpass query language.
- PHP library
spatie/data-transfer-object, should be installed automatically with Composer.
Configuration
Configuration form is located on `/admin/config/system/osm-localities` url, where you can configure preferred languages of OSM objects to import and other options.
Alternatives
I have found no alternatives for Drupal 8 with same functionality, so this is a main reason to make this module. Here are some alternative modules, that provides list of localities / cities:
- Country, State and City Fields - it uses a hard-coded non-updatable list of cities from unknown source. No boundary polygons.
- Country, State and City Field - this is a field only.
- Address - module provides list of countries, states and cities, but only in autocomplete form of the field widget.
- Cities - Drupal 7 version of module, not updated since 2014.
- Countries - Drupal 7 version of module, not updated since 2014.
- Address Field - Drupal 7 version of module, not updated since 2018.
Supporting this Module
You can convey gratitude to me for the development of the module and motivate me to do more through these services:

Project information
- Project categories: Integrations, Site structure
1 site reports using this module
- Created by murz on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.





