tags:

views:

197

answers:

2

I store the YQL WOEID (Where on earth id) for all the users of my application locations. I now need a way to search for all users within x miles of a given WOEID, is this possible using YQL?

Alternativly I guess I could change the app to store lat and longitudes, but I need the calculation of distances as quick as possible as there potentialy could be thousends of users.

Edit : I guess what I'm really looking for is something like the employee search on Stackoverflow Careers, where you can enter a place then tell it a distance around that space that you want to include in your search results

+2  A: 

As far as I can tell, this isn't something supported by YQL. The closest you might find is the method to return the neighbors of a given WOEID.

The problem with finding users within x miles of a given WOEID is that WOEIDs can be of arbitrary sizes with different centers and bounding boxes. Even though it is more complex, storing latitude and longitude are going to let you get the results you're looking for. There are at least two ways of going about this.

The first is to query directly on latitude and longitude by calculating the Haversine distance to the starting point. This can be extremely slow, especially when dealing with thousands of rows. In any event, you should see if your database support geospatial data. MySQL and PostgreSQL both have geospatial extensions.

A second popular method is to use a geohash. This produces a set of strings that you can use to query for nearby points. For example, take the coordinates Lat: 40.7571397, Lon: -73.9891705 for Rockefeller Center in NYC. One implementation of geohash (for Google AppEngine) for these coordinates produces the following:

  • 9
  • 9a
  • 9ac
  • 9ac7
  • 9ac7b
  • 9ac7be
  • 9ac7be2
  • 9ac7be2e
  • 9ac7be2e4
  • 9ac7be2e4e
  • 9ac7be2e4ed
  • 9ac7be2e4ed4
  • 9ac7be2e4ed4e

So if you want to find points that are really close, you can find other points that match 9ac7be2e4ed4e; if you want the general region you can try 9ac7be2e4e and so forth. Once you have a subset of your points, you could do the distance calculations on a much smaller dataset.

Ryan
A: 

Thanks, I did not know about geohash.

Walter