Collection of geotagged tweets from Twitter4j

Hello to 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 designed to collect tweets in the general location of the UK and Ireland, but does not collect tweets, and sometimes (rarely) collects tweets from areas outside the frame.

If I expand the bounding box, I get tweets, but sometimes they are outside the bounding box.

I work from logic that the 1st point of the bounding box is the angle SW, and the next point is the NE corner.

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

Thanks,

David

+4
source share
1 answer

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

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); 
+3
source

Source: https://habr.com/ru/post/1488046/


All Articles