arjunmehta / node-georedis

Super fast geo queries.
MIT License
192 stars 33 forks source link

pubnub malforms location coordinate latitude values #22

Closed richacker closed 7 years ago

richacker commented 7 years ago

Hi,

I am trying to store the lat long as: {"lat":29.419506,"long":79.038539}

But on querying the position, it returns: 27.80180134535769554 79.03853863477706909

Same is the case with any other position. Also the variation is not fixed.

arjunmehta commented 7 years ago

@richacker thanks for submitting the issue. Can you tell me whether you're using the native Redis implementation or the emulated?

Thanks!

richacker commented 7 years ago

@arjunmehta I am using emulated. Although on debugging I discovered that the issue is only on the case when I am inside the Pubnub listener. My code looks like this:

pubnub.addListener({
    message: function(message) {
        if (message.channel && message.channel.indexOf("gridapp.locations.") != -1) {
            var redis = require('redis'),
                client = redis.createClient()
            var geo = require('georedis').initialize(client);
            geo.addLocation('Toronto', { latitude: 43.6667, longitude: -79.4167 }, function(err, reply) {
                if (err) console.error(err)
                else console.log('added location:', reply)
            })
        }
    }
})

And on fetching the response is: Location for Toronto is: 41.26557858154362179 -79.4166979193687439

arjunmehta commented 7 years ago

@richacker Ahhh, very strange. Are you saying it works normally if you call addLocation outside of the pubnub.addListener?

arjunmehta commented 7 years ago

Also I should say, you should only initialize the module once...

Could you try changing your code to look more like:

var redis = require('redis');
var client = redis.createClient();
var geo = require('georedis').initialize(client);

pubnub.addListener({
    message: function(message) {
        if (message.channel && message.channel.indexOf("gridapp.locations.") != -1) {
            geo.addLocation('Toronto', { latitude: 43.6667, longitude: -79.4167 }, function(err, reply) {
                if (err) console.error(err)
                else console.log('added location:', reply)
            })
        }
    }
})
richacker commented 7 years ago

@arjunmehta I understand your concern for initializing the module once, but it throws the error: -ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / QUIT allowed in this context

And yes it works fine in normal context and only when it is in subscriber mode for pubnub listener or even in case of socket.io listeners, it shows this anomaly.

arjunmehta commented 7 years ago

@richacker Can you run redis-cli monitor (see here for usage)? This should give you some output. Run your app as it is, and copy/paste the output?

This would be super appreciated and greatly helpful!

Thank you!


An aside,

You should always create unique redis connection instances used exclusively for Pub, Sub and other queries.

Therefore, in your app, you should have 3 redis connections, one for pub, one for sub, and the other for things like georedis. Look into it here on StackOverflow.

However this still does not address the reason why you are experiencing these things. My guess is that the response is dropping the last digit from the geohash value (from the zscore) or something, and is not giving accurate results.

arjunmehta commented 7 years ago

I think this may be an issue with pubnub. I misunderstood, and didn't realize that you weren't using standard redis pub/sub.

Closing this issue as an edge case. Can open again if reported by others.