mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
Geo: use the high level API to decode in geoAppendIfWithinRadius()
This commit is contained in:
parent
0b93139048
commit
51b4a4724b
19
src/geo.c
19
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. */
|
* 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) {
|
int geoAppendIfWithinRadius(geoArray *ga, double x, double y, double radius, double score, sds member) {
|
||||||
GeoHashArea area = {{0,0},{0,0},{0,0}};
|
double distance, latlong[2];
|
||||||
GeoHashBits hash = { .bits = (uint64_t)score, .step = GEO_STEP_MAX };
|
|
||||||
double distance;
|
|
||||||
|
|
||||||
if (!geohashDecodeWGS84(hash, &area)) return REDIS_ERR; /* Can't decode. */
|
if (!decodeGeohash(score,latlong)) return REDIS_ERR; /* Can't decode. */
|
||||||
|
if (!geohashGetDistanceIfInRadiusWGS84(x,y,latlong[1], latlong[0],
|
||||||
double neighbor_y = (area.latitude.min + area.latitude.max) / 2;
|
radius, &distance))
|
||||||
double neighbor_x = (area.longitude.min + area.longitude.max) / 2;
|
{
|
||||||
|
|
||||||
if (!geohashGetDistanceIfInRadiusWGS84(x, y, neighbor_x, neighbor_y,
|
|
||||||
radius, &distance)) {
|
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Append the new element. */
|
/* Append the new element. */
|
||||||
geoPoint *gp = geoArrayAppend(ga);
|
geoPoint *gp = geoArrayAppend(ga);
|
||||||
gp->latitude = neighbor_y;
|
gp->latitude = latlong[0];
|
||||||
gp->longitude = neighbor_x;
|
gp->longitude = latlong[1];
|
||||||
gp->dist = distance;
|
gp->dist = distance;
|
||||||
gp->member = member;
|
gp->member = member;
|
||||||
gp->score = score;
|
gp->score = score;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user