Maps: Region Selection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jyamada
    Member
    • Aug 2026
    • 31

    #1

    Maps: Region Selection

    Trying to do something a bit above my pay grade so need help.

    When the user selects an address, I want to call a maps API to get the region/neighborhood, for example downtown. Problem is these are custom regions that do not match with google maps or OSM. So two questions:

    1) How should I host a lighter maps instance that can make these custom regions? OSM might work, but I don't know how to set it up and get my custom data in.
    2) How do I properly integrate it into espo? Making a custom formula function that makes the call pre save works, but if I need any libraries how do I include them?
  • eymen-elkum
    Active Community Member
    • Nov 2014
    • 506

    #2
    A full OSM instance is probably not necessary for this requirement. I would separate it into two steps:

    1. Geocode the selected address into latitude and longitude using your current provider, such as Nominatim or Google.
    2. Match that point against your own custom region polygons.

    Your region boundaries can be maintained as GeoJSON. For a small number of regions, point-in-polygon matching can run directly in an EspoCRM backend service. For a larger or frequently changing dataset, PostgreSQL/PostGIS or a small geospatial service would be more suitable; the lookup can use ST_Covers or ST_Contains.

    I would avoid making the external HTTP request directly from Formula during every save if possible. A timeout or provider error could block the user's save. A cleaner, update-safe EspoCRM extension would contain:

    - a backend geocoding service;
    - caching by normalized address;
    - a custom-region resolver;
    - a hook or queued job that writes the matched region to the record;
    - retry and logging for failed lookups.

    If the region must be available immediately, the service can be called from a before-save hook with a short timeout and cached results. Otherwise, processing it after save is safer.

    Third-party PHP libraries can be included through a module-level composer.json file and registered through Resources/autoload.json:



    Before choosing the architecture, it would help to know:

    - Are the custom boundaries already available as GeoJSON, KML, or Shapefile?
    - Approximately how many regions are there?
    - How often do the boundaries change?
    - Are latitude and longitude already stored in the EspoCRM record?

    The lightest solution will probably be external geocoding plus local GeoJSON matching rather than hosting the complete OSM stack.

    If needed, we can also implement this as an update-safe EspoCRM extension, starting with a small proof of concept to verify the matching accuracy and keep the total cost as low as possible.
    Eblasoft | EspoCRM specialists since 2014
    Consulting · Development · Integrations · Premium Extensions
    .

    Comment

    Working...