Search code examples
foursquare

foursquare search api with query and near parameters


I am using this api to search jack related data in city los gotas:

https://api.foursquare.com/v2/venues/search?near=los+gatos&query=jack&oauth_token=OUTH_TOKEN&v=20150728&categoryId=4d4b7105d754a06376d81259,4bf58dd8d48988d1fa931735,4bf58dd8d48988d10c941735,4bf58dd8d48988d1ea941735,4bf58dd8d48988d112941735&sortByDistance=1

but it also gives me data those are not relevant to that city.
here is the output:

{
      "vName": "Jack Barry and Associates",
      "vFourSquareID": "4f32c93919836c91c7fa7874",
      "enhance": "0",
      "vLogo": "",
      "bigthumb_logo": "",
      "compressthumb_logo": "",
      "vBanner": "",
      "bigthumb_banner": "",
      "compressthumb_banner": "",
      "iBarID": "-1",
      "tAddress": "Milpitas",
      "dLat": "37.425211",
      "dLong": "-121.866708",
      "distance": "0",
      "formatted_address": "2143 Incline Ct,Milpitas, CA 95035"
    },
    {
      "vName": "Jack O'Neill Lounge",
      "vFourSquareID": "52df337a498e8f50b076f933",
      "enhance": "0",
      "vLogo": "",
      "bigthumb_logo": "",
      "compressthumb_logo": "",
      "vBanner": "",
      "bigthumb_banner": "",
      "compressthumb_banner": "",
      "iBarID": "-1",
      "tAddress": "Santa Cruz",
      "dLat": "36.962198818189",
      "dLong": "-122.02405086867",
      "distance": "0",
      "formatted_address": "Santa Cruz, CA 95060"
    },
    {
      "vName": "Jack Rose Libation House",
      "vFourSquareID": "52a5a18511d28dac8af3d02d",
      "enhance": "0",
      "vLogo": "",
      "bigthumb_logo": "",
      "compressthumb_logo": "",
      "vBanner": "",
      "bigthumb_banner": "",
      "compressthumb_banner": "",
      "iBarID": "-1",
      "tAddress": "Los Gatos",
      "dLat": "37.240493163257",
      "dLong": "-122.00109243393",
      "distance": "0",
      "formatted_address": "18840 Saratoga Los Gatos Rd (Austin Way),Los Gatos, CA 95030"
    }

in the output, first 2 results are not from los gatos city. but still it is displaying. can anyone say why?


Solution

  • You are searching for nearby Los Gatos, but does not specify a range. You should use radius parameter to specify a range. Try following url

    https://api.foursquare.com/v2/venues/search?near=Los+Gatos&radius=5000&query=jack&oauth_token=(YOUR_TOKEN)&v=20150728&categoryId=4d4b7105d754a06376d81259,4bf58dd8d48988d1fa931735,4bf58dd8d48988d10c941735,4bf58dd8d48988d1ea941735,4bf58dd8d48988d112941735&sortByDistance=1