Ask A Question


You’re not receiving notifications from this thread.

Best way to measure distance between current user's location and place location?

Matias Fernandez asked in General

I'm building an app similar to Yelp. The user should have a current location (taken automatically) and a chosen location (defaulted to current location). Each place should also have a location. I would then take the difference between both the chosen location and the place location to get the distance. Then filter results based on distance. I don't really need more functionality than that.

I've researched some tools that might help such as Google Map's JS API and Ruby Geocoder, but I'm curious how you guys would tackle this.


I would probably use the Geocoder gem for this. You can back it with interchangeable APIs and cache results in Redis which is really handy.

Have you considered using the geosearch that's built into ElasticSearch? You can pass it in either a bounding box (like the coordinates of a Google Map embedded on the page like Yelp does if you drag the map), or you can search within a radius, so you can easily find things by km or miles away.

What's your UI going to look like for the interactions?


Here's a preview of how the site is going:

I actually have ElasticSearch already so geosearch might be the way to go. Thanks man.


This looks like a fun project! If you've already got elasticsearch going, it'll do really well to handle the search queries (plus it should handle the ordering from closes to furthest as well). Curious to hear how it goes man!


Perfect, I'll give it a try. Yeah, the project's been a blast! Couldn't have built it without your help!

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,038+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.