Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions GetOpenLocationCode.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ CREATE FUNCTION [dbo].[GetOpenLocationCode]
@longitude DECIMAL(9,6),
@codeLength INT = 10
)
RETURNS VARCHAR(MAX)
RETURNS VARCHAR(16)
AS
BEGIN
DECLARE @code VARCHAR(MAX) = '';
DECLARE @code VARCHAR(16) = '';
DECLARE @CodePrecisionNormal INT = 10; -- Provides a normal precision code, approximately 14x14 meters.
DECLARE @CodePrecisionExtra INT = 11; -- Provides an extra precision code, approximately 2x3 meters.
DECLARE @Separator CHAR(1) = '+'; -- A separator used to break the code into two parts to aid memorability.
Expand All @@ -44,9 +44,9 @@ BEGIN
IF (@latitude = @LatitudeMax)
BEGIN
DECLARE @latitudePrecission DECIMAL(9,6);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the improvements! And for pointing out the typo. Please change it also here on line 46 so I can merge your pull request. Thanks!

IF (@codeLength <= @CodePrecisionNormal) SET @latitudePrecission = POWER(@EncodingBase, @codeLength / -2 + 2);
ELSE SET @latitudePrecission = POWER(@EncodingBase, -3) / POWER(@GridRows, @codeLength - @PairCodeLength);
SET @latitude = @latitude - 0.9 * @latitudePrecission;
IF (@codeLength <= @CodePrecisionNormal) SET @latitudePrecision = POWER(@EncodingBase, (@codeLength / -2) + 2);
ELSE SET @latitudePrecision = POWER(@EncodingBase, -3) / POWER(@GridRows, @codeLength - @PairCodeLength);
SET @latitude = @latitude - 0.9 * @latitudePrecision;
END

-- Adjust latitude and longitude to be in positive number ranges.
Expand Down