summaryrefslogtreecommitdiff
path: root/src/geo.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-06-23 09:03:56 +0200
committerantirez <antirez@gmail.com>2015-06-23 09:03:56 +0200
commit51b4a4724b9570584ae1bbb0e30e3bf4d8db736a (patch)
tree7059036e80a64786ba8b9d71b66533cc49bccbae /src/geo.c
parent0b93139048c9e541feeaeacb79a604f50f6a2149 (diff)
downloadredis-51b4a4724b9570584ae1bbb0e30e3bf4d8db736a.tar.gz
Geo: use the high level API to decode in geoAppendIfWithinRadius()
Diffstat (limited to 'src/geo.c')
-rw-r--r--src/geo.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/geo.c b/src/geo.c
index dd7a1886c..eb79144ea 100644
--- a/src/geo.c
+++ b/src/geo.c
@@ -160,24 +160,19 @@ static inline void addReplyDoubleDistance(redisClient *c, double d) {
*
* returns REDIS_OK if the point is included, or REIDS_ERR if it is outside. */
int geoAppendIfWithinRadius(geoArray *ga, double x, double y, double radius, double score, sds member) {
- GeoHashArea area = {{0,0},{0,0},{0,0}};
- GeoHashBits hash = { .bits = (uint64_t)score, .step = GEO_STEP_MAX };
- double distance;
-
- if (!geohashDecodeWGS84(hash, &area)) return REDIS_ERR; /* Can't decode. */
-
- double neighbor_y = (area.latitude.min + area.latitude.max) / 2;
- double neighbor_x = (area.longitude.min + area.longitude.max) / 2;
+ double distance, latlong[2];
- if (!geohashGetDistanceIfInRadiusWGS84(x, y, neighbor_x, neighbor_y,
- radius, &distance)) {
+ if (!decodeGeohash(score,latlong)) return REDIS_ERR; /* Can't decode. */
+ if (!geohashGetDistanceIfInRadiusWGS84(x,y,latlong[1], latlong[0],
+ radius, &distance))
+ {
return REDIS_ERR;
}
/* Append the new element. */
geoPoint *gp = geoArrayAppend(ga);
- gp->latitude = neighbor_y;
- gp->longitude = neighbor_x;
+ gp->latitude = latlong[0];
+ gp->longitude = latlong[1];
gp->dist = distance;
gp->member = member;
gp->score = score;