-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgeo3x3.hsp
executable file
·72 lines (69 loc) · 1.5 KB
/
geo3x3.hsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#module
#defcfunc gex3x3_encode double lat, double lng, int level
if level < 1 {
Return ""
}
if lng < 0 {
res = "W"
flng = lng + 180.0
} else {
res = "E"
flng = lng
}
flat = lat + 90.0
unit = 180.0
repeat level - 1
unit = unit / 3.0
x = int(flng / unit)
y = int(flat / unit)
n = x + y * 3 + 1
res = res + n
flng = flng - double(x) * unit
flat = flat - double(y) * unit
loop
return res
#deffunc gex3x3_decode str code, array res2
unit = 180.0
lat = 0.0
lng = 0.0
level = 0
res2 = lat, lng, double(level), unit
clen = strlen(code)
if clen = 0 {
return
}
begin = 0
flg = 0
scode = code
c = strmid(scode, 0, 1)
if c = "-" | c = "W" {
flg = 1
begin = 1
} else {
if c = "+" | c = "E" {
begin = 1
}
}
level = 1
i = begin
repeat clen - 1
snum = "0123456789"
n = instr(snum, 0, strmid(scode, i, 1)) - 1
if n < 0 {
break
}
unit = unit / 3.0
lng = lng + double(n \ 3) * unit
lat = lat + double(n / 3) * unit
level = level + 1
i = i + 1
loop
lat = lat + unit / 2.0
lng = lng + unit / 2.0
lat = lat - 90.0
if flg {
lng = lng - 180.0
}
res2 = lat, lng, double(level), unit
return
#global