Skip to content

Commit 750a440

Browse files
committed
for recoverNearest, do not round lat/lon, instead use reference to ensure correct match. function description updated to match.
1 parent 14ba23d commit 750a440

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

python/openlocationcode.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,8 @@ def decode(code):
275275
to find the nearest matching full code.
276276
Returns:
277277
The nearest full Open Location Code to the reference location that matches
278-
the short code. Note that the returned code may not have the same
279-
computed characters as the reference location. This is because it returns
280-
the nearest match, not necessarily the match within the same cell. If the
281-
passed code was not a valid short code, but was a valid full code, it is
282-
returned unchanged.
278+
the short code. If the passed code was not a valid short code, but was a
279+
valid full code, it is returned unchanged.
283280
"""
284281
def recoverNearest(shortcode, referenceLatitude, referenceLongitude):
285282
if not isShort(shortcode):
@@ -295,11 +292,8 @@ def recoverNearest(shortcode, referenceLatitude, referenceLongitude):
295292
resolution = pow(20, 2 - (paddingLength / 2))
296293
# Distance from the center to an edge (in degrees).
297294
areaToEdge = resolution / 2.0
298-
# Now round down the reference latitude and longitude to the resolution.
299-
roundedLatitude = math.floor(referenceLatitude / resolution) * resolution
300-
roundedLongitude = math.floor(referenceLongitude / resolution) * resolution
301295
# Use the reference location to pad the supplied short code and decode it.
302-
codeArea = decode(encode(roundedLatitude, roundedLongitude)[0:paddingLength] + shortcode)
296+
codeArea = decode(encode(referenceLatitude, referenceLongitude)[0:paddingLength] + shortcode)
303297
# How many degrees latitude is the code from the reference? If it is more
304298
# than half the resolution, we need to move it east or west.
305299
degreesDifference = codeArea.latitudeCenter - referenceLatitude

0 commit comments

Comments
 (0)