lat lng + radius -> calculate in boundaries of

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):

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

1. Do the math yourself, or 2. Use the "geokit" gem <= that'd be my choice :slight_smile:

yes, this seems to be working: b = Geokit::Bounds.from_point_and_radius([c.latitude, c.longitude],c.distance)

p b.sw

from = [hdr.loclat, hdr.loclng]

to = [c.latitude, c.longitude]

if(b.contains?(from)) …

is this local calculation or does it make an API call?

I would think it'd be local, but to be certain I'd either

1. look at the source code 2. perform the calculation in a console while disconnected from     any network :slight_smile:

HTH,