Twitter location

Apr 15, 2015 at 1:13 PM
Hey,

I started doing some coding using your API and I have a small question.
I'm the stream part of the API, and I filter on certain words.
Now I want to filter on a specific location, like a country or something, but I have trouble finding out how the location works exactly.

do you draw a box between the 1st coordinate and the second ? or how does it work exactly.

Thanks!
Apr 18, 2015 at 12:46 PM
Hi,

Sorry for the long delays in the reply.
Yes you basically need to create a box. Or multiple boxes.

All the tweets within any of these coordinates will be returned by Twitter.
If you use the Filter Stream please be aware of the difference between StartStreamMatchingALLConditions and StartStreamMatchingANYCondition.

https://tweetinvi.codeplex.com/discussions/539444

Linvi
Marked as answer by linvi on 4/18/2015 at 4:46 AM
Apr 21, 2015 at 10:40 AM
Hi,

Tweets contains a Coordinates property.
var coordinates = tweet.Coordinates;
You can use this to determine whether a tweet is in a specific location.
public static bool CoordinatesLocatedIn(ICoordinates coordinates, ILocation location)
{
    return CoordinatesLocatedIn(coordinates, location.Coordinate1, location.Coordinate2);
}

public static bool CoordinatesLocatedIn(ICoordinates coordinates, ICoordinates boxCoordinates1, ICoordinates boxCoordinates2)
{
    bool xIsBelowCoord1AndAboveCoord2 = boxCoordinates1.Longitude >= coordinates.Longitude &&
                                            coordinates.Longitude >= boxCoordinates2.Longitude;

    bool xIsAboveCoord1AndBelowCoord2 = boxCoordinates1.Longitude <= coordinates.Longitude &&
                                        coordinates.Longitude <= boxCoordinates2.Longitude;

    bool yIsRightCoord1AndLeftCoord2 = boxCoordinates1.Latitude >= coordinates.Latitude &&
                                        coordinates.Latitude >= boxCoordinates2.Latitude;

    bool yIsLeftCoord1AndRightCoord2 = boxCoordinates1.Latitude <= coordinates.Latitude &&
                                        coordinates.Latitude <= boxCoordinates2.Latitude;

    return (xIsAboveCoord1AndBelowCoord2 || xIsBelowCoord1AndAboveCoord2) &&
            (yIsLeftCoord1AndRightCoord2 || yIsRightCoord1AndLeftCoord2);
}
Cheers,
Linvi
Apr 21, 2015 at 10:48 AM
Also FilteredStream contains an event that will allow you to get all the matching locations.
filteredStream.MatchingTweetAndLocationReceived += (sender, args) =>
{
    var locations = args.MatchedLocations;
};
Linvi