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 ?
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?
I would break this problem up into several steps:
Pick an appropriate S2-Level for your application. In your case, since you're querying by 5 KM radii, I'd pick level 13 cells, that have an average size of 1.27 km^2.
Generate a level-13 cell covering of the 5 KM radius around the person.
Get a level-13 cell from the lat/lng of the car.
Do a contains check of the car S2 Cell to the 5 KM radius S2 Cell covering.
Here is an example with the Node.js JavaScript S2 Library:
You can visualize what this looks like with Sidewalk Lab's S2 map tool: