Question

We're trying to use the foursquare API to find the x nearest places to a user within a particular category. Following the guidelines under the foursquare API, https://developer.foursquare.com/docs/venues/search , and this github repo https://github.com/wallabyfinancial/foursquare-api-java , we ran the following code and received only one hit

1
Whisknladle

The query should return us more than one location. When we tried to change the long/lat to manhattan, we received 0 results. Any idea why this happens or how to solve it? We tried changing the null values to empty strings and changing values but nothing worked.

Attached is the code we used.

    package fi.foyt.foursquare.example;

    import fi.foyt.foursquare.api.FoursquareApi;
    import fi.foyt.foursquare.api.FoursquareApiException;
    import fi.foyt.foursquare.api.Result;
    import fi.foyt.foursquare.api.entities.CompactVenue;
    import fi.foyt.foursquare.api.entities.VenuesSearchResult;

    /**
     * Basic search example
     * @TODO - more examples please :)
     * @author rmangi
     *
     */

public class BasicExample {

  public static void main(String[] args) {
    String ll = args.length > 0 ? args[0] : "32.8400, 117.2769";
      //String ll = "40.7903, 73.9597";
      try {
      (new BasicExample()).searchVenues(ll);
    } catch (FoursquareApiException e) {
      // TODO: Error handling
        System.out.println(e.getMessage());
    }
  }

  public void searchVenues(String ll) throws FoursquareApiException {
    // First we need a initialize FoursquareApi. 
    FoursquareApi foursquareApi = new FoursquareApi("AKHMSYBUPITCRX3UWOC4CBH2YQFI3X5LSTYCJ4PMFHEMRJBT", "WFDOPMHICSVZ0Q3F5OODJV1RHCA4C1A0CBEFKXADXUXJAHVR", "https://api.foursquare.com/v2/");

    // After client has been initialized we can make queries.
   Result<VenuesSearchResult> result = foursquareApi.venuesSearch(ll, null, null, null, null, null, null, null, null, null, null, null, null);
    System.out.println("testingddddd");
    if (result.getMeta().getCode() == 200) {
      // if query was ok we can finally we do something with the data
      for (CompactVenue venue : result.getResult().getVenues()) {
        // TODO: Do something we the data
          System.out.println(result.getResult().getVenues().length);
        System.out.println(venue.getName());
      }
    } else {
      // TODO: Proper error handling
      System.out.println("Error occured: ");
      System.out.println("  code: " + result.getMeta().getCode());
      System.out.println("  type: " + result.getMeta().getErrorType());
      System.out.println("  detail: " + result.getMeta().getErrorDetail()); 
    }
  }

}

Was it helpful?

Solution

The reason you are only receiving one hit for that code is that it would appear that foursquare is expecting the latitude and longitude to be expressed as negative for positions west and south (of the prime meridian and equator respectively) and positive for positions east and north.

If you change the coordinate string you are passing to "32.8400, -117.2769" then you should get lots of venues returned near La Jolla, CA. (Whisknladle is listed as being in China although this is a problem with the data for that venue).

If you change to the coordinates you have commented out for Manhattan you have the same problem which is that the longitude coordinate needs to be negative i.e. "40.7903, -73.9597". You get lots of odd results for the coordinates you have there which returns venues that are named as though they are in Manhattan but have their country listed as Kyrgyzstan (which is where "40.7903, 73.9597" is. I guess this is again a problem with their data.

Also there are two other things to note:

  1. I had two remove the final two nulls from the line

    Result<VenuesSearchResult> result = foursquareApi.venuesSearch(ll, null,
     null, null, null, null, null, null, null, null, null, null, null);
    

    but I'm not sure if that is due to my using a different version of the foursquare-api-java library

  2. You should edit out your secret key from the code you posted :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top