Spatial index/query (finding k nearest points)

后端 未结 3 1095
星月不相逢
星月不相逢 2021-02-11 03:34

I have +10k points (latitude, longitude) and I\'m building an app that shows you the k nearest points to a user\'s location.

I think this is a very common problem and I

3条回答
  •  情歌与酒
    2021-02-11 03:43

    If you want to use MongoDB, then read their docs carefully. The default model is flat earth. It assumes that a degree of longitude has the same length as a degree of latitude.

    I quote: """The current implementation assumes an idealized model of a flat earth, meaning that an arcdegree of latitude (y) and longitude (x) represent the same distance everywhere. This is only true at the equator where they are both about equal to 69 miles or 111km. However, at the 10gen offices at { x : -74 , y : 40.74 } one arcdegree of longitude is about 52 miles or 83 km (latitude is unchanged). This means that something 1 mile to the north would seem closer than something 1 mile to the east."""

    You need their "new spherical model". Be warned: you need to use (longtitude, latitude) in that order -- again, read their docs carefully.

提交回复
热议问题