问题
It would be extremely helpful if an "order_by" & "sort" parameter could be passed in the api querystring.
"order_by" should accept the following options: distance | checkins | name
"sort" should accept the following options: asc | desc
The matched result set should have the order_by and sort parameters applied prior to narrowing the result set to the max "50" results that get returned.
Is this on the foursquare radar or is it something that will not be offered?
We are building an app that lets users locate "restaurants" closest to them based on the device's geolocation.
The issue we are having is in setting the default radius. We started by setting the radius to 3200 meters, hoping that that would return at lease some results for sparse locations while also returning the closest results for dense locations.
This works for locations that return less than 50 because we can sort post response, but in a dense area such as Washington DC, when there are more than 50 results the 50 that the api decides to return are NOT the closest to the ll.
Therefore we have to structure our query as shown below (which sucks cause it requires upto 7 hits to the api) to try to find that "sweet spot" of just under 50 results.
This is the issue we are encountering for "near me" locations in our app. We have a similar issue when trying to display "popular" venues in the app, but I'll save that for another post.
ob_start();
require_once 'includes/EpiCurl.php';
require_once 'includes/EpiFoursquare.php';
$clientId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$fsObjUnAuth = new EpiFoursquare($clientId, $clientSecret);
$time_start2 = microtime(true);
$result = $fsObjUnAuth->get('/venues/search', array(
'categoryId' => '4d4b7105d754a06374d81259',
'limit' => '50',
'radius' => '100',
'intent' => 'checkin',
'll' => $ll,
'v' => '20120211'
));
$result_count1 = count($result->response->venues);
if ($result_count1 < 30) {
$result = $fsObjUnAuth->get('/venues/search', array(
'categoryId' => '4d4b7105d754a06374d81259',
'limit' => '50',
'radius' => '200',
'intent' => 'checkin',
'll' => $ll,
'v' => '20120211'
));
$result_count2 = count($result->response->venues);
if ($result_count2 < 30) {
$result = $fsObjUnAuth->get('/venues/search', array(
'categoryId' => '4d4b7105d754a06374d81259',
'limit' => '50',
'radius' => '400',
'intent' => 'checkin',
'll' => $ll,
'v' => '20120211'
));
$result_count3 = count($result->response->venues);
if ($result_count3 < 30) {
$result = $fsObjUnAuth->get('/venues/search', array(
'categoryId' => '4d4b7105d754a06374d81259',
'limit' => '50',
'radius' => '800',
'intent' => 'checkin',
'll' => $ll,
'v' => '20120211'
));
$result_count4 = count($result->response->venues);
if ($result_count4 < 30) {
$result = $fsObjUnAuth->get('/venues/search', array(
'categoryId' => '4d4b7105d754a06374d81259',
'limit' => '50',
'radius' => '1200',
'intent' => 'checkin',
'll' => $ll,
'v' => '20120211'
));
$result_count5 = count($result->response->venues);
if ($result_count5 < 30) {
$result = $fsObjUnAuth->get('/venues/search', array(
'categoryId' => '4d4b7105d754a06374d81259',
'limit' => '50',
'radius' => '1600',
'intent' => 'checkin',
'll' => $ll,
'v' => '20120211'
));
$result_count6 = count($result->response->venues);
if ($result_count6 < 30) {
$result = $fsObjUnAuth->get('/venues/search', array(
'categoryId' => '4d4b7105d754a06374d81259',
'limit' => '50',
'radius' => '3200',
'intent' => 'checkin',
'll' => $ll,
'v' => '20120211'
));
$result_count7 = count($result->response->venues);
}
}
}
}
}
}
回答1:
There's no plan to offer such parameters. For the most part, these parameters are only useful for developers scraping all venues in a region, which is in violation of the foursquare terms of service
There are three different "intents" offered which correspond to valid use cases requiring different types of ranking.
intent=checkin returns a list of venues where the user is most likely is located
intent=browse returns a list of most relevant venues for a requested region, not biased by distance from a central point.
intent=match returns a single result that, with high confidence, is the corresponding foursquare venue for the query-based request
来源:https://stackoverflow.com/questions/9520904/is-there-an-api-order-by-sort-parameter-in-the-works