Store Locator | Geolocation | Location Search | using PostgreSQL GiST #21075
Replies: 3 comments 6 replies
-
I have a need for this use-case. We have a store locator currently that needs to be ported and I was trying to figure out how to do this. I would need a zipcode db. I see this which is neat but doesnt have attached zip codes: |
Beta Was this translation helpful? Give feedback.
-
absolutely needed feature!!! i tried a quick POC with extensions, it is possible to build |
Beta Was this translation helpful? Give feedback.
-
@br41nslug IDK the plugin is pretty easy to add, but point noted. After all the mapbox integration in Directus is using these features already so it's already a dependency for some geospatial stuff. The postgis database image is widely available. The Pro Cloud and Enterprise editions support it. But again, I understand and appreciate your thoughts. Thank you for your input. @Oreilles and @Nitwel since you were involved with the maps integration, I wonder if you had any input on this search/filter/sort concept? |
Beta Was this translation helpful? Give feedback.
-
Summary
This feature exposes the PostgreSQL GIST functionality via Global Parameters and Filters enabling users and administrators to search and sort items by distance from a point.
Basic Example
In this basic example, we are calling an API to reveal a list of items that are located within the distance of the coordinates specified.
Motivation
Sometimes it makes sense to search items geospatially. This is useful for the following reasons.
The easiest example to consider is a Store Locator. On a retailers website, users want to search by zip code and receive a list of stores sorted by distance from that location. In this example the front end would accept an input for zip code. The front end will will determine the zip code's latitude and longitude information via an external service such as Google maps API, or potentially via a zip code database which would be loaded into the Directus database (separately configured by the website administrator, not this extension). Ultimately, the front end will submit the latitude and longitude for the point of interest. The directus API will return a list of items that have latitude and longitude data within x miles or kilometers from the initial point.
Detailed Design
I think this can be done as an extension to extend the filter/search capabilities of Directus. I hope to get input from the Directus team on how to maintain filtering standards so that the extension maintains high compatibility with the Directus ecosystem.
The Directus API must take lat/long values as an input, and return a list of objects sorted by distance from that original location. The data being queried must have Lat/Long values already populated in the data model (Map Field). No geocoding is being suggested for this extension. All Lat/Long conversions are done by the user or front end developer. Geocoding is another feature altogether.
PostgreSQL GIST has geo-spacial search functionality built it, we are using some of those features in the Directus Admin to show maps and filter items by boundaries. This feature will expose some of these features in the Directus API (via an extension) so that we can submit a latitude and longitude and it will return items sorted by distance.
Requirements List
Must Have:
Drawbacks
This will not work with MySQL because GIST is required and only installed with PostgreSQL + GIST. Otherwise this should be a non-breaking change.
Alternatives
This can be done using an external API such as google distance matrix. This would require fees, The PostgreSQL GIST implementation is "free" with the database engine. Being highly integrated with the Directus API would enable a slew of opportunities for application developers.
Adoption Strategy
Hopefully the filter parameters can maintain the same formatting and style as the rest of the filters. This should not be a breaking change, just a new feature.
Unresolved Questions
None at this time. This feature is open to discussion.
Beta Was this translation helpful? Give feedback.
All reactions