1.GEO是什么?
GEO图解 应用场景2. 五个城市经纬度
five cities3.相关命令
#添加地理位置信息
geoadd key longitude latitude member [longitude latitude member ...]
# 获取地理位置信息
geopos key member [member ...]
#获取2个地理位置的距离
#unit m(米)、km(千米)、mi(英里)、ft(尺),默认是米
GEODIST key member1 member2 [unit]
#radius 英[ˈreɪdiəs] n. 半径(长度); 半径范围; 周围; 桡骨
#withcoord : 返回结果中包含经纬度。
#withdist :返回结果中包含距离中心节点位置
#withhash : 返回结果中包含geohash
#COUNT count : 指定返回结果的数量
#asc | desc 返回结果按照距离中心节点的距离做升序或者降序
#store key : 将返回结果的地理位置信息保存到指定键
#storedist key : 将返回结果距离中心节点的距离保存到指定键
georadius key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count]
georadiusbymember key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [AS
实战例子
127.0.0.1:6379> geoadd cities:locations 116.28 39.55 beijing
(integer) 1
127.0.0.1:6379> geoadd cities:locations 116.28 39.55 beijing
(integer) 0
127.0.0.1:6379> geoadd cities:locations 117.12 39.08 tianjin
(integer) 1
127.0.0.1:6379> geoadd cities:locations 118.01 39.38 tangshan
(integer) 1
127.0.0.1:6379> geoadd cities:locations 114.29 38.02 shijiazhuang 115.29 38.51 baoding
(integer) 2
127.0.0.1:6379> geopos cities:locations beijing
1) 1) "116.28000229597091675"
2) "39.5500007245470826"
127.0.0.1:6379> geodist cities:locations tianjin beijing
"89206.0576"
127.0.0.1:6379> geodist cities:locations tianjin beijing km
"89.2061"
127.0.0.1:6379> GEORADIUSBYMEMBER cities:locations bejing 150 km
(error) ERR could not decode requested zset member
127.0.0.1:6379> GEORADIUSBYMEMBER cities:locations beijing 150 km
1) "beijing"
2) "tianjin"
3) "tangshan"
4) "baoding"
127.0.0.1:6379> type cities:locations
zset
4.相关说明
1). Since 3.2
2). type geoKey = zset
3). 没有删除API:使用zrem key member
网友评论