Use GEORADIUS with Lat/Long coordinates

11 views
Skip to first unread message

Michael Kolber

unread,
Aug 5, 2018, 7:01:11 AM8/5/18
to Redis DB
Hello,

Is it possible to use coordinates to describe the radius for a GEORADIUS command? I know I can use the Haversine formula to get an actual distance, and use that, but since I already have the latitude and longitude of the radius given to me, I would prefer to use that rather than have to calculate the radius each time.

Thank you.

Itamar Haber

unread,
Aug 5, 2018, 7:20:21 AM8/5/18
to Redis DB
Hello Michael,

No - presently the `GEORADIUS[BYMEMBER][_RO]` commands do not support calculating the radius from a lat/lon pair. Until this functionality is added, if at all, you should continue performing the calculation.

Note, however, that you can call `GEODIST` to obtain the radius if you add the provided coordinate temporarily to the GeoSet. This could, arguably, be wrapped into a Lua script such as:

local gs = KEYS[1]                -- the geoset
local ele = ARGV[1]               -- the element in the geoset
local lon, lat = ARGV[2], ARGV[3] -- lon and lat of the "radius"
local tmp = ARGV[4]               -- some random unique value

redis.set_repl(redis.REPL_NONE)
redis.call('GEOADD', gs, lon, lat, tmp)
local rad = redis.call('GEODIST', gs, ele, tmp)
redis.call('ZREM', gs, tmp)
return redis.call('GEORADIUSBYMEMBER', gs, ele, rad, 'm')

Cheers,




--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--

Itamar Haber
Technicalist Evangenly

Phone: +972.54.567.9692

Redis Labs


Michael Kolber

unread,
Aug 5, 2018, 8:15:39 AM8/5/18
to Redis DB
This is great, thank you! !תודה רבה :)
Reply all
Reply to author
Forward
0 new messages