Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

New Post: Twitter location

$
0
0
Hi,

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

publicstaticbool 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

Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>