2

In my app, a user is at a location and is looking for her friends who have been anywhere withing 10 miles of where she is. How do I find this with either FQL or graph? The only way that I can see is by running a search like so: https://graph.facebook.com/search?type=checkin and then running through the results to find out which location was within 10 miles. Is there a better way for this?

Thanks for your help!

Doles

doles
  • 558
  • 6
  • 20

2 Answers2

2

From http://developers.facebook.com/docs/reference/fql/location_post/

It says

An FQL table that returns Posts that have locations associated with them and that satisfy at least one of the following conditions:

  • you were tagged in the Post
  • a friend was tagged in the Post
  • you authored the Post
  • a friend authored the Post

Note: This query can process a large amount of data. In order to ensure that a manageable amount of data is returned within a reasonable timeframe, you should specify a recent timestamp to narrow the results.

Return posts within 10,000 meters of a given location:

SELECT id, page_id
FROM location_post
WHERE distance(latitude, longitude, '37.86564', '-122.25061') < 10000
DMCS
  • 31,720
  • 14
  • 71
  • 104
  • Thank you! I followed your doc link and also tried the fql from your post as well as from the reference. Some of them worked and others did not. In any case, my current purpose is solved. Thank you very much. – doles Jun 06 '12 at 16:12
  • I am unable to upvote because i need at least 15 repu points and i have only one. :) – doles Jun 06 '12 at 16:13
  • You can accept an answer without 15 reputation points. Click the grey checkmark and make it green. :) – DMCS Jun 07 '12 at 20:06
  • 1
    DCMS: if facebook locations are still of interest to you, you should see my new answer to my own post. Thank you. – doles Oct 14 '12 at 16:35
2

Although the initial answer did work for me for part of my purpose, it quickly became inadequate. Now, after banging my head against the wall, it finally broke (not my head - the wall). Here are two more BETTER ways that WORK to find what I need:

This is to find just checkins:

SELECT checkin_id, coords, tagged_uids, page_id FROM checkin WHERE (author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) or author_uid=me()) and coords.latitude<'45.0' and coords.latitude>'29' and coords.longitude>'-175' and coords.longitude<'-5';

This is to find all location posts:

SELECT id, page_id FROM location_post WHERE (author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) or author_uid=me()) and coords.latitude<'45.0' and coords.latitude>'29' and coords.longitude>'-175' and coords.longitude<'-5'

elp
  • 8,021
  • 7
  • 61
  • 120
doles
  • 558
  • 6
  • 20
  • Good find, Facebook is always changing things, and it appears this is on the of nicer additions to their API. – DMCS Dec 31 '12 at 20:55