MongoDB Bound Queries: How do I convert mile to radian?

前端 未结 2 1209
无人共我
无人共我 2021-02-02 14:18

I have a collection of stores with a geospacial index on the location propery.

What I am trying to do is given the user\'s latitude, latitude and a search radius (mi), I

2条回答
  •  粉色の甜心
    2021-02-02 15:01

    As docs say:

    All distances use radians. This allows you to easily multiply by the radius of the earth (about 6371 km or 3959 miles) to get the distance in your choice of units. Conversely, divide by the radius of the earth when doing queries.

    so you simple need to divide your radius by the earth radius. in your example it would be:

    radius = 10/3959

提交回复
热议问题