Skip to main content

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

General • Asked by Matias Fernandez

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:

http://www.drinklist.io/

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!


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.