Jim Jones
Jim Jones

Reputation: 161

Node.js server side solution to find user location

Please educate me for i am hoping this is possible. I am working on a mobile app that is currently using Node.js on its backend server side. Using twitter's api I am currently streaming tweets from from a static location (for example New York City):

twit.stream('statuses/filter',{ 'locations':'-74,40,-73,41'}, 
function(stream) {
        stream.on('data', function(data)

Is there anyway that i can adjust this code where if the user moves, tweets are now automatically streamed from their new location?

In other words if the user is now in Miami Florida, my goal is to have the server now automatically stream tweets from that area; and the same if they were to drive to Gainesville Florida or fly to Atlanta Georgia etc...

I need Nodejs to automatically stream tweets from the user's new location. Is there anyway to do so?

I assume that I have to create a variable var location = latitude, longitude Where would I go from there?

Here is an example of my code:

var twitter = require('ntwitter');
var twit = new twitter({
    consumer_key: credentials.consumer_key,
    consumer_secret: credentials.consumer_secret,
    access_token_key: credentials.access_token_key,
    access_token_secret: credentials.access_token_secret
});

//Streaming from the static location of New York City
twit.stream('statuses/filter',{ 'locations':'-74,40,-73,41'}, 
function(stream) {
        stream.on('data', function(data) {


            console.log(data.text);

Upvotes: 2

Views: 1470

Answers (1)

Neil Cresswell
Neil Cresswell

Reputation: 1165

The most reliable option with the best location granularity would be to pass the geolocation lat/lon over from your mobile app. The only down side to this is that your app (assuming Android or iOS) will ask the user if it's OK to share the geolocation information from your app, but the user is only asked once. You don't provide more details re your mobile app, but if it's written using PhoneGap / Apache Cordova, feel free to ping me if some code snippets would be helpful.

The other option is to pass on the IP and do an IP location lookup with a service. However, this typically can be very unreliable and you can often be off as in the wrong state even.

With both options, keep in mind it's easy to spoof the wrong location.

Upvotes: 1

Related Questions