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

New Post: Hi! I created a stream and besides the text of a tweet, I want to get the coordinates.

$
0
0
Hello,

The coordinates are not always available in a Tweet.
Lots of users decide to not publish their coordinates as part of their public tweets.

Therefore you need to always check if the Coordinates property of a tweet is not null.
privatestaticvoid TwitterStream()
{
    var stream = Stream.CreateSampleStream();

    stream.TweetReceived += (sender, args) =>
    {
        var tweet = args.Tweet;
                
        var hasUserPublishedWithLocation = tweet.Coordinates != null;
        if (hasUserPublishedWithLocation)
        {
            Console.WriteLine(tweet.Coordinates.Latitude);
        }
    };
            
    stream.StartStream();
}
Linvi

Viewing all articles
Browse latest Browse all 4126

Trending Articles