How to perform the Search operation when i have Thousands of Points

Skip to first unread message

Koteswara Siva Kumar Devineni

Aug 28, 2019, 2:01:47 AM8/28/19
to s2geometry-io
I have geo location of vehicles and my point in the city and I need to find those vehicles that are within 5kms radius of my point.
I could represent the vehicle locations and my point with S2 cell id. But how can i query ?

Do I need to load data for all the Vehicle locations in memory and then use S2 library to find my target users.
Or can I store data for all the users in a database and make query on S2 cell ids.
As S2 cell id is using Hilbert curve, Can we know those vehicles which have closer S2 cell ids are closer in distance with each other.

Or is there any other method which i have to use here to perform the search operation?

Please suggest..

Martin Phee

Sep 6, 2019, 10:08:12 AM9/6/19
to Koteswara Siva Kumar Devineni, s2geometry-io
I've been playing around with this myself.  If you have any thoughts I would be interested.

So for my simple solution, I did this in Go. 

var point = s.Point{Lat: 51.4622952, Lng: -0.1994539}
rc := &s2.RegionCoverer{MaxLevel: 20, MaxCells: 10}
covering := s.S2CellIdsCoveringGivenRadius(500, point, rc)
for _, c := range covering {

pipeline := redisRepo.Pipeline()
var results []*redis.StringSliceCmd
for _, c := range covering {
results = append(results, createQuery(c, pipeline))

cmds, err := pipeline.Exec()
if err != nil {
func createQuery(c s2.CellID, pipeline redis.Pipeliner) *redis.StringSliceCmd {
// perform a range lookup in the DB from bmin key to bmax key, cur is our DB cursor
//var cell s2.CellID
result := pipeline.ZRangeByScore("branches", redis.ZRangeBy{
Min: strconv.FormatInt(int64(c.RangeMin()), 10),
Max: strconv.FormatInt(int64(c.RangeMax()), 10),
if result.Err() != nil {

return result

You received this message because you are subscribed to the Google Groups "s2geometry-io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages