Skip to content

GEODIST

The GEODIST command in DiceDB is used to calculate the distance between two members (geospatial points) stored in a geospatial index(set).

Syntax

Terminal window
GEODIST key member1 member2 [m | km | ft | mi]

Parameters

ParameterDescriptionTypeRequired
keyThe name of the sorted set where the geospatial data is stored.stringYes
member1The name of the member1 from where you want to measure the distance.stringYes
member2The name of the member2 to where you want to measure the distance.stringYes
mThe distance to be measured in meters.NONENO
kmThe distance to be measured in kilometers.NONENO
ftThe distance to be measured in feet.NONENO
miThe distance to be measured in miles.NONENO

Return Values

ConditionReturn Value
If both members exist in the set with no optiondistance b/w them in meters
If both members exist in the set with option kmdistance b/w them in kilometers
If both members exist in the set with option ftdistance b/w them in feet
If both members exist in the set with option midistance b/w them in miles
If any member doesn’t exist in Setnil
Incorrect Argument CountERR wrong number of arguments for 'geodist' command

Behaviour

When the GEODIST command is issued, DiceDB performs the following steps:

  1. It gets the sorted set(key).
  2. It gets the scores(geohashes) from the sorted sets for both the members.
  3. It calculates the distance bw them and returns it.

Errors

1.Wrong number of arguments for 'GEODIST' command

  • Error Message: (error) ERR wrong number of arguments for ‘geodist’ command.
  • Occurs when the command is executed with an incorrect number of arguments.

Example Usage

Here are a few examples demonstrating the usage of the GEODIST command:

Example : Adding new member to a set

Terminal window
127.0.0.1:7379> GEOADD cities -74.0060 40.7128 "New York"
1
127.0.0.1:7379> GEOADD cities -79.3470 43.6510 "Toronto"
1
127.0.0.1:7379> GEODIST cities "New York" "Toronto"
"548064.1868"
127.0.0.1:7379> GEODIST cities "New York" "Toronto km"
"548.0642"
127.0.0.1:7379> GEODIST cities "New York" "Toronto mi"
"340.5521"