-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathGeo3x3.obs
63 lines (61 loc) · 1.38 KB
/
Geo3x3.obs
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
Function Geo3x3_encode(lat, lng, level)
If level < 1 Then
Return ""
End If
res = "E"
If lng < 0 Then
res = "W"
lng = lng + 180.0
End If
lat = lat + 90.0
unit = 180.0
For i = 1 To level - 1
unit = unit / 3.0
x = Int(lng / unit)
y = Int(lat / unit)
n = x + y * 3 + 1
res = res & n
lng = lng - x * unit
lat = lat - y * unit
Next
Geo3x3_encode = res
End Function
Function Geo3x3_decode(code)
clen = Len(code)
If clen = 0 Then
Return ""
End If
begin = 1
flg = 0
c = Mid(code, 1, 1)
If c = "-" or c = "W" Then
flg = 1
begin = 1
ElseIf c = "+" or c = "E" Then
begin = 1
End If
unit = 180.0
lat = 0.0
lng = 0.0
level = 1
For i = begin To clen - 1
n = InStr("0123456789", Mid(code, i + 1, 1)) - 1
If n <= 0 Then
Exit For
End If
unit = unit / 3
n = n - 1
lng = lng + (n mod 3) * unit
lat = lat + Int(n / 3) * unit
level = level + 1
Next
lat = lat + unit / 2.0
lng = lng + unit / 2.0
lat = lat - 90.0
If flg Then
lng = lng - 180.0
End If
Geo3x3_decode = Array(lat, lng, level, unit)
End Function
WScript.Echo Geo3x3_encode(35.65858, 139.745433, 14)
WScript.Echo Join(Geo3x3_decode("E9139659937288"))