maps application - best way to store co-ordinates in MongoDB -
i'm making maps application. have co-ordinates of bunch of locations. want return points within area visible on screen. done google maps api. gives north-east , south-west co-ordinates of map visible on screen. i'm using mongodb.
the obvious way take midpoint of ne-sw diagonal center, distance either corner radius, , find points within radius.
but storing them in single list o(n) operation - not scalable every request. better way of storing them able points quickly?
i'm thinking of splitting them buckets contain points within radius(r), , maintain sorted list of buckets instead. since screen can on 4 buckets at-most (every corner on separate bucket), find closest bucket in o(log n) , next 3 closest ones in o(1). have computations these 4 buckets.
but that's still lot of buckets! google able render points on map quickly. , have lot of points. , lot of users. how manage that? don't expect reach level of optimization, there's got better data structure.
maybe i’m not understanding…. solution sounds pretty complicated..
you have screen corners - ne long , lat , sw long , lat therefore have sw_lat, sw_long, ne_lat, sw_lat
you want select points within boundary… if have long & lat stored decimal use pseudo code of :
select * points point_lat > sw_lat , point_lat < ne_lat , point_long > sw_long , point_long < ne_long
that fill visible screen.
Comments
Post a Comment