Geolocate the tweets in nodejs

1

I am trying to perform a geolocation of tweets using the twitter API, I am using a statuses / filter type stream to check the tweets, and the position data I am taking from coordinators, but when consulting, it returns only the position of very few tweets, there is another way to check the position. This is how I do it now.

client.stream('statuses/filter', {track: criteria },  function(stream) {
        stream.on('error', function(error) {
            console.log(error);  
        });
    stream.on('data', function(data) {
             jsonTweet = {
                    "id": data.id,
                    "user":"@" + data.user.screen_name,
                    "date": data.timestamp_ms,
                    "name": data.name,
                    "text": prep(data.text),
                    "language": data.lang,
                    "coordinates": data.coordinates
                        }
                      })    
    
asked by Paul 08.03.2017 в 17:59
source

1 answer

0

There is no way to get more results (or rather, there is no way to place tweets without position) but what you can do is, for example, filter by an array of coordinates (bounding box) wide enough to cover the whole area that interests you:

client.stream('statuses/filter', {
        locations: [-130, -57, -60, 0]
    },  function(stream) {
    ...
    }
);

In this case the tweets without position could not comply with the locations parameter, so they would not come in the result.

If you use this method, and also want to track for a certain term, it will not work, because that criterion is met for tweets that meet the term or that are in the range of locations That is, it is an OR clause.

An additional fact: if you specify locations, you will get tweets that meet one of the two conditions:

  • Tweets with coordinates (that are inside the bounding box)
  • Tweets that have the place attribute and whose bounding box overlaps with your bounding box.
  • Since a tweet has a bounding box, then you can geolocate the tweet to the center of the bounding box.

    In other words, given a locations criterion, the tweets that come will have coordinates or will have place, and the geolocalizations like:

    if (data.coordinates) {
        jsonTweet = {
          "id": data.id,
          "user":"@" + data.user.screen_name,
          "date": data.timestamp_ms,
          "name": data.name,
          "text": prep(data.text),
          "language": data.lang,
          "coordinates": data.coordinates
        };
    } else if (data.place && data.place.bounding_box) {
    
        var SW = data.place.bounding_box.coordinates[0][0],
            NE = data.place.bounding_box.coordinates[0][2];
    
        data.coordinates = {
            type: "Point",
            coordinates: [(SW[0] + NE[0]) / 2, (SW[1] + NE[1]) / 2]
        };
    
        jsonTweet = {
          "id": data.id,
          "user":"@" + data.user.screen_name,
          "date": data.timestamp_ms,
          "name": data.name,
          "text": prep(data.text),
          "language": data.lang,
          "coordinates": data.coordinates
        };
    
    }
    

    More information at Stream API #Locations

        
    answered by 08.03.2017 / 19:02
    source