Search code examples
javatwittertwitter4j

Get tweet by location with tweet4j


I want to get the tweet in Hanoi.

1) I have use the search query but I receive duplicate tweet,how to avoid that?

Query query = new Query(queryString);
       GeoLocation city = new GeoLocation(latitude, longitude);
       query.geoCode(city, 20, "mi");

2) What is tweetID? Is it increase by time?Can I use query.setSinceId(); with the maxID from last retrive?

3) I try other way by use the stream to get Tweet but its receive tweet not in area I want(ex: from china or Laos) Am I was wrong?

 double lat = 21.082647;
 double lon = 105.822526;
 double lon1 = lon - 0.05;
 double lon2 = lon + 0.05;
 double lat1 = lat - 0.05;
 double lat2 = lat + 0.05;
 double box[][] = {{lon1, lat1}, {lon2, lat2}};
 fq.locations(box);

Solution

  • Twitter's API searches for geotagged tweets first and falls back to the users profile location if a tweet isn't explicitly geotagged. This could be the reason your search is returning tweets from locations outside your boundary.

    For example:

    Suppose your searching Hanoi's geolocation for tweets containing a query. The search will return explicitly geotagged tweets from Hanoi containing the query. The search will also return tweets from a different geolocation containing the query by users with a profile location of Hanoi.