Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
51b4a472
Commit
51b4a472
authored
Jun 23, 2015
by
antirez
Browse files
Geo: use the high level API to decode in geoAppendIfWithinRadius()
parent
0b931390
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/geo.c
View file @
51b4a472
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment