Clustering Lat/Longs in a Database

前端 未结 6 1816
南旧
南旧 2020-12-23 23:18

I\'m trying to see if anyone knows how to cluster some Lat/Long results, using a database, to reduce the number of results sent over the wire to the application.

The

6条回答
  •  既然无缘
    2020-12-23 23:56

    I did a similar thing for a geographic application where I wanted to ensure I could cache point sets easily. My geohashing code looks like this:

    def compute_chunk(latitude, longitude)
      (floor_lon(longitude) * 0x1000) | floor_lat(latitude)
    end
    
    def floor_lon(longitude)
      ((longitude + 180) * 10).to_i
    end
    
    def floor_lat(latitude)
      ((latitude + 90) * 10).to_i
    end
    

    Everything got really easy from there. I had some code for grabbing all of the chunks from a given point to a given radius that would translate into a single memcache multiget (and some code to backfill that when it was missing).

提交回复
热议问题