4

Hi All,

   public static void main(String[] args) {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("xxxxxx");
    cb.setOAuthConsumerSecret("xxxx");
    cb.setOAuthAccessToken("xxxx");
    b.setOAuthAccessTokenSecret("xxxxxxx");

    TwitterStream twitterStream = new    TwitterStreamFactory(cb.build()).getInstance();

    StatusListener listener = new StatusListener() {

        @Override
        public void onException(Exception arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice arg0) {
            // TODO Auto-generated method stub

        }

        @Override
            public void onScrubGeo(long arg0, long arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStatus(Status status) {
            User user = status.getUser();

            // gets Username
            String username = status.getUser().getScreenName();
            System.out.println(username);
            String profileLocation = user.getLocation();
            System.out.println(profileLocation);
            long tweetId = status.getId(); 
            System.out.println(tweetId);
            String content = status.getText();
            System.out.println(content +"\n");
            GeoLocation geolocation = status.getGeoLocation();

            System.out.println(geolocation +"\n");


        }

        @Override
        public void onTrackLimitationNotice(int arg0) {
            // TODO Auto-generated method stub
            System.out.println("onTrackLimitationNotice" +"\n");

        }

        @Override
        public void onStallWarning(StallWarning arg0) {
            // TODO Auto-generated method stub
            System.out.println("onStallWarning" +"\n");

        }

    };
    FilterQuery fq = new FilterQuery();
    double lat = 53.186288;
    double longitude = -8.043709;
    double lat1 = lat - 4;
    double longitude1 = longitude - 8;
    double lat2 = lat + 4;
    double longitude2 = longitude + 8;
    twitterStream.addListener(listener);
    double[][] bb= {{lat1,longitude1}, {lat2 ,longitude2}};

    // fq.track(keywords);
    fq.locations(bb);


    twitterStream.filter(fq);  

}

This code is to collect tweets in the general UK & Ireland location but doesn't collect tweets or sometimes (rarely) collects tweets from areas outside the bounding box.

If i widen the bounding box I do get tweets but again sometimes they are outside the bounding box.

I am working from the logic that the 1st point of the bounding box is SW corner and next point is NE corner.

Any ideas what could be the problem? I am using Twitter4j 3.0.3

Thanks,

David

David Crowley
  • 51
  • 2
  • 7
  • For example when running this code I got a tweet from -4.65842064, 55.40764413 which is in the Seychelles....so obviously my logic is wrong somewhere as my bounding box should be {{49.186288, -16.043709}, {57.186288, 0.043709}}? and this tweet should be way outside it – David Crowley Jun 25 '13 at 11:02

1 Answers1

3

I think you are sending the coordinates in the wrong order. According to Filter Spec, Twitter expects a comma-separated list of longitude,latitude, but you are sending (latitude,longitude) pairs.

The correct version should be:

double lat = 53.186288;
double longitude = -8.043709;
double lat1 = lat - 4;
double longitude1 = longitude - 8;
double lat2 = lat + 4;
double longitude2 = longitude + 8;

double[][] bb = {{longitude1, lat1}, {longitude2, lat2}};

FilterQuery fq = new FilterQuery();
fq.locations(bb);
twitterStream.filter(fq);  
edrabc
  • 1,259
  • 1
  • 14
  • 23
  • Yes - that works thanks. Sorry was thinking the way i would say it "latitude and longitude" – David Crowley Jun 25 '13 at 13:33
  • I also noticed that I still get tweets that return the geolocation as "null" - wonder why the API gives me these tweets? – David Crowley Jun 25 '13 at 15:25
  • 1
    Just did the same request with curl and returned valid coordinates field for each tweet: ... "coordinates":{"type":"Point","coordinates":[-1.27016675,52.99986186]} ... Looks like the response is the expected and each tweet matches the location filter. – edrabc Jun 26 '13 at 11:35