Sorting the response from the Foursquare Places API re:two word name? - api

We are trying to query the Foursquare api to query for a two word name:
Cava Grill in Gaithersburg, MD
We are trying this via:
https://api.foursquare.com/v2/venues/search?intent=checkin&query=cava%20grill&near=gaithersburg,%20md&limit=1&oauth_token=SEB14NBLGO4HMFTOXQX0JZTSVGM41ENNKE0X1RXHCI5XP3P5&v=20150420
(don't worry ... this is the public API key from the FS page)
Two odd behaviors:
Even though we are explicitly searching for the Cava Grill in Gaithersburg, MD ... the Bethesda, MD one comes up first in the results (odd, why??)
Chipotle Mexican Grill shows up in this result set ... we suppose because of the word "Grill"
So ...
a. anyone know why the Bethesda one would show up higher in the result set? (Should we just narrow the radius tighter?)
b. anyone know if we can look for the "entire query" vs. each word in the query?

Results are queried and sorted differently based on your intent. If you're looking for a specific venue, I suggest changing your intent from checkin to match. Browse may also be a good choice depending on future search params
Here's the nutshell on the intents:
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
I hope this helps

Related

How to use http://www.census.gov API to pull data

Am trying to query data from http://www.census.gov, using their API
I want to get the population of a particular city in the US, by using the city name and the US state code.
Given that I already have the key, what other parameters do I add in the URL below, so that I can get the population.
http://api.census.gov/data/2010/sf1?key=<my key>
any assistance will be greatly appreciated
Judging from your query URI, you wish to access population data from the 2010 Census Summary File. You would add GET paramaters of get and for to your query. Example:
http://api.census.gov/data/2010/sf1?key=b48301d897146e8f8efd9bef3c6eb1fcb864cf&get=P0010001&for=state:06
The population table as given in the get parameter are identified with a "P" and you can use the for parameter to further narrow down your scope. Examples of valid criteria formatted as URIs can be found here...
EDIT: It seems that for a finer grained search such as cities, you're going to need to use the governments cumbersome FIPS (Federal Information Processing Standard) codes (after converting lat/lon regions to their coding system)... I've found this resource that should be helpful, specifically points 5 thru 7, but it seems mega complex...
Another alternative I found is the USA Today census API, it seems that they mirror the data from the census and they do have available endpoints with data granularity at the city level... Check it out here...
no need to use API the data is available in CSV here http://www.census.gov/popest/data/cities/totals/2012/SUB-EST2012.html

Why does Foursquare search not return venues closest to my specified location?

I'm noticing something odd with foursquare search API. When I specify a latitude and longitude of a location in my city, I'm not getting venues that are closest to me.
For search parameters I'm using:
ll = 47.620918,-122.318455 (a neighborhood in Seattle, WA)
intent = browse
radius = 48 280 (approx 30 miles)
categoryId = 4d4b7105d754a06374d81259 (food), 4d4b7105d754a06376d81259 (nightlife)
venues/search?ll=47.620918,-122.318455&intent=browse&radius=42820&categoryId=4d4b7105d754a06374d81259,4d4b7105d754a06376d81259
I would expect this query to return me venues that are closest to the specified lat+long location and in the food or nightlife categories. This isn't what I'm seeing. Instead, the first venue in the array is a venue that is 768 meters away, the second is 2162 meters, the third is 722 meters.
There are food and nightlife venues that are much closer than 700 meters to that latitude and longitude.
One could argue that I should take the results and sort them myself based on the distance attribute but this seems flawed for 2 reasons:
If the venue list being returned isn't closest to my location, I'm missing out on a lot of venues since they couldn't all fit within the max limit of the query results. So even if I sorted based on distance attribute, I'm only sorting venues that shouldn't be considered nearby.
The reason I specify a lat+long to the search API is to have foursquare do the heavy lifting for me on what is "nearby". If I need to sort then what's the point? There's an argument to be made that foursquare shouldn't return venues that are more relevant to you, but this is why I'm using intent=browse instead of intent=checkin'
For intent=browse, the docs say:
Find venues within a given area. Unlike the checkin intent, browse searches an entire region instead of only finding Venues closest to a point.
what am I doing wrong such that I'm not getting the closest venues return to the specified lat+long?
Just like the docs say, when you use intent=browse, Foursquare doesn't "only [find] Venues closest to a point." When you use intent=browse with a ll/radius, imagine this as setting up a region and asking Foursquare for the "best" results from this region. It is not saying "find me the results starting at this ll growing until the radius."
In general, Foursquare search does not guarantee results in any particular order unless it's specified under the description for the intent, and unfortunately none of these specify that the results will be returned sorted by increasing radius.
I know this is a old thread, just wanted to let people know that you can use sortByDistance=1 as parameter to sort venues the closest to the location.

CategoryId in venues search not working correctly

In foursquare Api documentation for "Search venues" https://developer.foursquare.com/docs/venues/search it states
"categoryId - A comma separated list of categories to limit results to. This is an experimental feature and subject to change or may be unavailable. If you specify categoryId you may also specify a radius. If specifying a top-level category, all sub-categories will also match the query."
Realise its supposed to be experimental, but when I provide Food category i.e. 4d4b7105d754a06374d81259, it only returns a few local results, the rest are miles away. However if I execute same search on website sing Food category, it returns correctly lots of results, assuming its the last bit "If specifying a top-level category, all sub-categories will also match the query" is not working , i.e. its not searching sub-categories ?
Any fix work around for this ?
Thanks,
Neil Pepper
You're making a /venues/search request with its default intent of intent=checkin. This returns a filter on nearby results, heavily biased by distance since it's trying to guess where the user might be checking in.
Foursquare Explore uses the /venues/explore endpoint and attempts to return recommended results for a query. If you want to get the sorts of results you get in that tool, call /venues/explore?section=food

Venue Search API Inaccurate Using "Near" Instead of "LL"

When I search venues via API I get different results than the foursquare website. For example I'm looking for a venue named "Nopalito" near "San Francisco, CA". I'm under the impression this should return relevant matches:
https://api.foursquare.com/v2/venues/search?query=Nopalito&intent=match&near=San%20Francisco%2C%20CA
I only receive one result for a venue named "Invocation". However, when I run a similar query via foursquare.com website I get what I'd expect:
https://foursquare.com/search?tab=venueResults&q=Nopalito&lat=&lng=&near=San+Francisco%2Cca&source=q
The website search yields two venues named Nopalito in San Francisco, CA.
Seems like a very basic query with a limited number of potential results. What's up? Am I missing something obvious here?
At first glance I'd suggest dropping intent=match, intent=match makes a very restrictive query. The purpose of intent=match (from https://developer.foursquare.com/docs/venues/search ) is to
"Finds venues that are are nearly-exact matches for the given query and ll. This is helpful when trying to correlate an existing place database with foursquare's. It is highly sensitive to the provided location. The results will be sorted best match first, taking distance and spelling mistakes/variations into account."
I'd recommend intent=browse for this type of query.

Flickr Geo queries not returning any data

I cannot get the Flickr API to return any data for lat/lon queries.
view-source:http://api.flickr.com/services/rest/?method=flickr.photos.search&media=photo&api_key=KEY_HERE&has_geo=1&extras=geo&bbox=0,0,180,90
This should return something, anything. Doesn't work if I use lat/lng either. I can get some photos returned if I lookup a place_id first and then use that in the query, except then all the photos returned are from anywhere and not the place id
Eg,
http://api.flickr.com/services/rest/?method=flickr.photos.search&media=photo&api_key=KEY_HERE&placeId=8iTLPoGcB5yNDA19yw
I deleted out my key obviously, replace with yours to test.
Any help appreciated, I am going mad over this.
I believe that the Flickr API won't return any results if you don't put additional search terms in your query. If I recall from the documentation, this is treated as an unbounded search. Here is a quote from the documentation:
Geo queries require some sort of limiting agent in order to prevent the database from crying. This is basically like the check against "parameterless searches" for queries without a geo component.
A tag, for instance, is considered a limiting agent as are user defined min_date_taken and min_date_upload parameters — If no limiting factor is passed we return only photos added in the last 12 hours (though we may extend the limit in the future).
My app uses the same kind of geo searching so what I do is put in an additional search term of the minimum date taken, like so:
http://api.flickr.com/services/rest/?method=flickr.photos.search&media=photo&api_key=KEY_HERE&has_geo=1&extras=geo&bbox=0,0,180,90&min_taken_date=2005-01-01 00:00:00
Oh, and don't forget to sign your request and fill in the api_sig field. My experience is that the geo based searches don't behave consistently unless you attach your api_key and sign your search. For example, I would sometimes get search results and then later with the same search get no images when I didn't sign my query.