Redis GEOPOS – How to get longitude, latitude of multiple members of geospatial value
2 months ago Lalit Bhagtani 0
In this tutorial, we will learn about how to get longitude, latitude of one or more members of geospatial value stored at a key, by using a COMMAND – GEOPOS in redis-cli.
This command is used to return the longitude, latitude of one or more specified members of geospatial value ( Sorted Set ) stored at a key. When coordinates ( longitude, latitude ) are inserted into geospatial value by using GEOADD command, they are converted into a 52 bit geohash. So when coordinates are returned, they may not be exactly the same one used during insertion operation but can contain small errors. It returns an array where each element is an array of two elements representing longitude and latitude of each specified member member.
Empty array is returned when key does not exist and error is returned when key exist but value stored at the key is not of sorted set datatype which is populated using GEOADD command.
The syntax of redis GEOPOS command is as follows :-
redis host:post> GEOPOS <member> [member]
- (string) reply, representing the longitude and latitude of specified members. - Empty array, if key does not exist. - Error, if key exist and value stored at the key is not a sorted set populated using GEOADD command.
That’s all for how to get the longitude, latitude of one or more members of geospatial value stored in redis datastore. If you liked it, please share your thoughts in comments section and share it with others too.