Building a Power-Packed Multi-Filter Search: Location, Type, and Distance in Rails with Geocoder

by | May 22, 2025 | Ruby On Rails | 0 comments

Building a Power-Packed Multi-Filter Search: Location, Type, and Distance in Rails with Geocoder

I encountered a major challenge while creating a directory for local businesses: designing an intuitive search interface that allows users to easily find listings by location and property type. I aimed to create a strong real-time search experience, starting with a solid foundation for future improvements.

This first iteration focuses on three core user needs:

  • Finding listings by property type
  • Searching by location
  • Adjusting search radius to expand or narrow results

By omitting JavaScript in this version, we guarantee that the search functions in all browsers, ensuring a consistent experience. Future versions will use Turbo for real-time updates and a more dynamic interface. This version shows how to create a clean, functional geographic search using only Rails and Geocoder.

The solution outlined below uses Bootstrap’s floating labels for a modern feel, while maintaining a straightforward form submission process. It’s a great foundation for any location-based directory system, like property listings, business directories, or apps needing geographic search.

Let’s dive into how to implement this foundation, which you can later enhance with progressive improvements.

Model Setup

Rails code example: multi-filter search using Geocoder for location, type, and distance.
Shares
  • Facebook
  • Twitter
  • LinkedIn
Rails code example: multi-filter search using Geocoder for location, type, and distance.

Controller

Rails code example: multi-filter search using Geocoder, permitting listing type ID, location (near), and distance.
Shares
  • Facebook
  • Twitter
  • LinkedIn
Rails code example: multi-filter search using Geocoder, permitting listing type ID, location (near), and distance.

View

Rails code example: multi-filter search by location, property type, and distance.
Shares
  • Facebook
  • Twitter
  • LinkedIn
Rails code example: multi-filter search by location, property type, and distance.

Required Database Columns

Rails migration adding latitude and longitude columns to listings table for location-based search.
Shares
  • Facebook
  • Twitter
  • LinkedIn
Rails migration adding latitude and longitude columns to listings table for location-based search.

Geocoder Configuration

# config/initializers/geocoder.rb
Geocoder.configure(
  units: :mi,
  distances: :linear
)

Required CSS

Add Bootstrap to your application:

# app/assets/stylesheets/application.scss
@import "bootstrap";

.form-floating {
  > label {
    z-index: 3;
  }

  > .form-select {
    padding-top: 1.625rem;
    padding-bottom: 0.625rem;
  }
}

Key Features

  • Location-based search using Geocoder
  • Predefined search radiuses
  • Property type filtering
  • Bootstrap 5 floating labels
  • Responsive card grid for results
  • Distance calculation for search results

Requirements

  • Ruby on Rails 7.0+
  • Bootstrap 5
  • Geocoder gem
  • PostgreSQL (recommended for geographic queries)

Remember to:

  1. Run migrations
  2. Add appropriate address validation
  3. Configure Geocoder API keys if needed
  4. Add appropriate indexes for performance
  5. Consider rate limiting for production use

Conclusion: It’s Time for You to Experience Geo-Amazing! 🌍

Well, there you have it – a clean, functional geographic search that doesn’t need JavaScript to be awesome! But this is just the beginning of our location-based adventure.

What’s Next?

Watch for the enhanced version of this tutorial, where we’ll create a smooth, real-time search experience using Hotwire/Turbo. Subscribe to stay updated!

Useful Links

  • Geocoder – The gem that makes geographic magic happen
  • Bootstrap – For those floating labels and responsive goodness
  • Turbo – Sneak peek at what’s coming next!

Let’s Chat!

I’d love to hear from you:

  • What features would you add to this search?
  • Are you building something similar? What challenges are you facing?
  • Have you found creative ways to use Geocoder in your projects?

Drop a comment below, and let’s geek out about geographic search together! If you found this helpful, don’t forget to like and share – it helps other developers find this resource.

Show & Tell

Built something cool with this tutorial? Share your project in the comments! There’s nothing better than seeing what the community creates.

And remember, even T-Rex had small arms, but that didn’t stop him from being awesome – start small, iterate often! 🦖

P.S. If you’re impatient for the Turbo version, throw a “🚀” in the comments, and I’ll know to speed things up!

Need a Rails Expert? Let's Chat!

If you’re looking for someone to help bring your Rails project to life, I’m available for consulting work. If you need assistance with creating a new application, fixing an old codebase, or adding complex features, I’d love to help.

From quick code reviews to long-term partnerships, I work with startups, established companies, and everyone in between. I am based in Australia but happy to work with teams globally.

Ready to make your Rails app brilliant? Book A Consultation or connect on LinkedIn. Let’s discuss how I can help turn your ideas into reality.


P.S. Not quite ready for a full project? I also offer one-off consultation calls to help you get unstuck or validate your approach. Sometimes a fresh pair of experienced eyes is all you need!

Follow Us

Subscribe

About The Author

Jeremy is the founder of heyjeremy.com, a developer who specialises in Ruby on Rails, WordPress, and Shopify's Liquid framework. He is based in the Gold Coast hinterland, Australia, where he uses his technical skills to create innovative web solutions. When not coding, Jeremy enjoys exploring with his rescue dog Max, a Kelpie-Husky mix, trying new technologies, and looking for authentic Mexican food.

More Reading

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Share This

Share this post with your friends!