-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
on decodeGeo3x3(code) | ||
set unit to 180.0 | ||
set lat to 0.0 | ||
set lng to 0.0 | ||
set level to 1 | ||
|
||
set begin to 0 | ||
set flg to false | ||
set c to character 1 of code | ||
if c = "-" or c = "W" then | ||
set flg to true | ||
set begin to 1 | ||
else if c = "+" or c = "E" then | ||
set begin to 1 | ||
end if | ||
set clen to length of code | ||
repeat with i from begin to clen - 1 | ||
set c to character (1 + i) of code | ||
set n to c as integer | ||
if n <= 0 then | ||
break | ||
end if | ||
set unit to unit / 3 | ||
set n to n - 1 | ||
set lng to lng + n mod 3 * unit | ||
set lat to lat + n div 3 * unit | ||
set level to level + 1 | ||
end repeat | ||
set lat to lat + unit / 2 | ||
set lng to lng + unit / 2 | ||
set lat to lat - 90.0 | ||
if flg then | ||
set lng to lng - 180.0 | ||
end if | ||
return { lat: lat, lng: lng, level: level, unit: unit } | ||
end decodeGeo3x3 | ||
|
||
log decodeGeo3x3("E9139659937288") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
on encodeGeo3x3(lat, lng, level) | ||
if level < 1 then | ||
return "" | ||
end if | ||
set res to "" | ||
set lng2 to lng | ||
if lng >= 0 then | ||
set res to "E" | ||
else | ||
set res to "W" | ||
set lng2 to lng2 + 180 | ||
end if | ||
set lat2 to lat + 90.0 | ||
set unit to 180.0 | ||
repeat level - 1 times | ||
set unit to unit / 3 | ||
set x to lng2 div unit | ||
set y to lat2 div unit | ||
set res to res & (x + y * 3 + 1) | ||
set lng2 to lng2 - x * unit | ||
set lat2 to lat2 - y * unit | ||
end repeat | ||
return res | ||
end encodeGeo3x3 | ||
|
||
log encodeGeo3x3(35.65858, 139.745433, 14) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters