how to find friend's past checkins near a loca

2020-06-28 00:52发布

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

2条回答
相关推荐>>
2楼-- · 2020-06-28 01:27

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
查看更多
Lonely孤独者°
3楼-- · 2020-06-28 01:36

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'

查看更多
登录 后发表回答