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

Ask A Question

Notifications

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:

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!

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.