Ruby on Rails Friday, August 17, 2018

> On Aug 17, 2018, at 12:59 PM, tom <tomabroad@gmail.com> wrote:
>
> hi,
>
> i have a Task model with and address plus radius in miles (adress is being translated to lat/lng via geo-api-call).
>
> Now i have a person at location x and i want to know if that person is within that circle of the TaskModel's location plus radius.
>
>
> does anyone know how to calculate that w/o using geo-api calls?
>
>
> thx
> tom


That's called the great-circle distance. It's not overly complex to implement by hand (I've done it in SQL and in app code in the past):

https://en.wikipedia.org/wiki/Great-circle_distance

You might need to be careful about using floats, as they aren't perfectly accurate (funny rounding stuff can happen which could cause exceptions). Maybe use BigDecimal if doing your calculation with your own ruby code.

Hope that helps.


Phil

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/EC5E7899-D1EF-431F-B7D0-17A55B63784C%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment