Geospatial search

Hi, is possible to implement a “find my nearest” geo search in Redwoodjs? I’ve searched the docs, etc but can’t find anything. If it’s doable would you mind pointing me in the right direction?
Thanks!

Have you looked into the Google Maps API? The Places API specifically says:

The functions in the Places Library, Maps JavaScript API enable your application to search for places (defined in this API as establishments, geographic locations, or prominent points of interest) contained within a defined area, such as the bounds of a map, or around a fixed point.

Here’s an article on building a Maps component in React: Fullstack React: How to Write a Google Maps React Component

Would require bringing in a third party service but we’ve got lots of built-in integrations with StepZen that would make this pretty simple to implement since we’ve already got connectors to popular APIs like the IP Geolocation API.

You can then link that IP to all sorts of other useful information such as their location or weather. Here’s a sample repo using Redwood and StepZen together. I could build out a proof of concept this weekend if this sounds interesting to you.

Using third party API is the way to go, especially if you need to sort by driving distance, not geographical distance.

But just for information: If you’re planning to use Postgres as DB of your choice, you have the option to setup PostGIS along with it - which will enable you to do all kinds of Geospatial queries. But there doesn’t seem to be Prisma support for PostGIS as of now: PostGIS support · Issue #2789 · prisma/prisma · GitHub (which you’ll want for easily querying from your services).
You can probably get away with Unsupported field and raw queries but it will not be a great development and maintenance experience. It won’t be the Redwood way. :grinning_face_with_smiling_eyes:

EDIT: And oh, the PostGIS approach will be only applicable for the point/places you have defined. To search for any random place, an external API would be the only choice.

2 Likes

And you’ll need a postgres db with the postgis extension installed to go down that route.
One such option is supabase

1 Like

Nice! I like both Supabase and Postgres, I didn’t know it comes with PostGIS pre-configured (100 points to Supabase). Now, if we just have Prisma support for it, that’ll be the last piece of the puzzle.

Supabase recently added the pgRouting extension, too:

https://supabase.io/new/blog/2021/07/26/supabase-postgres-13#new-extensions

https://pgrouting.org

1 Like

That should cover driving distance too! That’s nice. (Given we have all required data to perform routing - GeoJSON features)

2 Likes