arjunmehta / node-georedis

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

coordinates entered are not exactly same as original #19

Closed vvavepacket closed 7 years ago

vvavepacket commented 7 years ago

Lets say we have the following coordinate which we want to add

longitude,latitude 121.16625075805472,14.55976969490166

Now, if we try to insert it using node-georedis, it was inserted successfully, but the inserted coordinates are different from original. Why is that?

longitude,latitude 121.16625219583511353,14.55976912035422544

arjunmehta commented 7 years ago

Hi @vvavepacket Yes, both Redis' implementation (c++) and the backup emulated implementation (javascript) methods of storing the coordinates use geohashing, which is only precise up to a certain number of decimal places. Both are limited by the maximum system floating point (64bit for c++, 52 for javascript). In fact geohashes are actually just boxes of a certain accuracy. Because of this the coordinates will change slightly because when they are stored they only refer to an area of a given accuracy, and not a very specific point.

You can learn more about the general algorithm used by this module here and also learn about geohashing here.

I hope this helps!