Reputation: 1661
I have a array of latitude and longitude and a center point.
{
center: {
lat: 10.002,
lng: 20.003
},
all: [
{
lat: 20,
lng: 50
},
{
lat: 10,
lng: 20.000001
},
// ...
]
}
I would like to know how do I get nearby locations in 10km or other specific range. Does there any keyword or library can help me do this?
Upvotes: 1
Views: 464
Reputation: 1748
you can use geohash.
standard geohash can give you a good starting point, since the hash represents the location so you can group by the hash on certain mask based on your precision.
refer to: https://en.wikipedia.org/wiki/Geohash
this method is simple and there are lots of libraries out there.
but it also suffers from pole distortion and edge cases.
however I have implemented an alternative algorithm to solve those problems: https://github.com/linehrr/geohash
the drawback is that precision is pre-determined, so masking won't work since it's not linear.
hope this helps.
Upvotes: 1