Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nearby with range #72

Open
lairtonmendes opened this issue Jan 18, 2019 · 1 comment
Open

Nearby with range #72

lairtonmendes opened this issue Jan 18, 2019 · 1 comment

Comments

@lairtonmendes
Copy link

Hello dear,

I need make this query below, but I need set the maxDistance por exemplo 1000 meters
Bar.nearby(my.location)

In MongoDB documentation

{
   <location field>: {
     $near: {
       $geometry: {
          type: "Point" ,
          coordinates: [ <longitude> , <latitude> ]
       },
       $maxDistance: <distance in meters>,
       $minDistance: <distance in meters>
     }
   }
}

thank you very munch

@thiensubs
Copy link

thiensubs commented Aug 18, 2020

@lairtonmendes
Maybe you can apply code bellow:

 lat = params[:lat].to_f
 lng = params[:lng].to_f
 # i'm using distance with kilometer, if you using meter, please convert it.
 radius = params[:distance].to_f / 111.12
 radius_min = params[:distance_min].to_f / 111.12
 aps = Model.where(location: { "$nearSphere": [lng, lat], "$maxDistance": radius,  "$minDistance": radius_min}).to_a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants