Search code examples
javascriptjavatwittertwitter4j

Using Twitter api, how to display tweets from a selected group based on geo location


So I am working on a project, and needed to integrate latest tweets from a selected group of people. The challenge is that I want to display the tweets/feeds based on geo location of readers - In other words someone (reader) in NYC will see tweets from people in the selected group that lives in NYC area.

Questions: 1. Are there tools out there that anyone can suggest to making this task easier? 2. Can twitter API be manipulated to provide such results?

Suggestions will very much be appreciated. Thanks.


Solution

  • You can combine the with navigator.geolocation API with the Twitter API Geolocation search - see here

    Then to determine the user's location use the navigator's built in navigator.geolocation.getCurrentPosition() function which you can then use when making the request to Twitter.

    The following function will provide the user's latitude and longitude.

    navigator.geolocation.watchPosition(function(position) {
      var latitude = position.coords.latitude;
      var longitude = position.coords.longitude;
    });