16,554
社区成员
发帖
与我相关
我的任务
分享
Dim address As String
Private Function GetAddress(ByVal digits As Integer, ByVal lon As Double, ByVal lat As Double)
Const Pi = 3.1415926535897
Dim x As Double
Dim y As Double
Dim quad As String
Dim lookup(4) As String
Dim i As Integer
Dim m As Integer
Dim n As Integer
digits = Val(Text3.Text)
lon = Val(Text1.Text)
lat = Val(Text2.Text)
x = (180# + lon) / 360#
y = -lat * Pi / 180#
y = 0.5 * Log((1 + Sin(y)) / (1 - Sin(y)))
y = y * (1# / (2 * Pi))
y = y + 0.5
quad = "t"
lookup(0) = "q"
lookup(1) = "r"
lookup(2) = "t"
lookup(3) = "s"
For i = 1 To digits
x = x - Int(x)
y = y - Int(y)
If x >= 0.5 Then
m = 1
Else
m = 0
End If
If y >= 0.5 Then
n = 2
Else
n = 0
End If
quad = quad + lookup(m + n)
x = x * 2
y = y * 2
Next i
GetAddress = quad
End Function
Function GetNextTileX(ByVal addr As String, ByVal forward As Boolean)
If addr = "" Then
addr = addr
End If
Dim parent As String
Dim last As String
parent = Left(addr, Len(addr) - 1)
last = Right(addr, 1)
If last = "q" Then
last = "r"
If Not forward Then
parent = GetNextTileX(parent, forward)
End If
ElseIf last = "t" Then
last = "s"
If Not forward Then
parent = GetNextTileX(parent, forward)
End If
ElseIf last = "r" Then
last = "q"
If forward Then
parent = GetNextTileX(parent, forward)
End If
ElseIf last = "s" Then
last = "t"
If forward Then
parent = GetNextTileX(parent, forward)
End If
End If
GetNextTileX = parent + last
End Function
Function GetNextTileY(ByVal addr As String, ByVal forward As Boolean)
If addr = "" Then
addr = addr
End If
Dim parent As String
Dim last As String
parent = Left(addr, Len(addr) - 1)
last = Right(addr, 1)
If last = "q" Then
last = "t"
If Not forward Then
parent = GetNextTileY(parent, forward)
End If
ElseIf last = "r" Then
last = "s"
If Not forward Then
parent = GetNextTileY(parent, forward)
End If
ElseIf last = "s" Then
last = "r"
If forward Then
parent = GetNextTileY(parent, forward)
End If
ElseIf last = "t" Then
last = "q"
If forward Then
parent = GetNextTileY(parent, forward)
End If
End If
GetNextTileY = parent + last
End Function
Function DoRebuild()
Dim addr As String
Dim cursor As String
Dim i As Integer
Dim j As Integer
Dim n As Integer
n = 0
addr = GetAddress(Val(Text3.Text), Val(Text1.Text), Val(Text2.Text))
cursor = Left(addr, Val(Text3.Text))
cursor = GetNextTileX(cursor, False)
cursor = GetNextTileY(cursor, False)
Label1.Width = 0
For i = 1 To 3
Dim c2 As String
c2 = cursor
cursor = GetNextTileX(cursor, True)
For j = 1 To 3
n = n + 1
address = "http://kh.google.com/kh?v=3&t=" + c2
c2 = GetNextTileY(c2, 1)
List1.AddItem address
Download address, "c:\map\" & CStr(j) & "-" & CStr(i) & ".jpg"
Label1.Width = (n / 900) * Picture1.Width
Label2.Caption = "正在下载:" + CStr(n / 9) + "%"
Next j
Next i
End Function
Private Sub Download(UrtFile As String, localfile As String)
Dim bData() As Byte '数据变量
Dim intfile As Integer '可用文件变量
Dim i As Integer
Dim ttt As String
Dim c As String
Dim h() As String
intfile = FreeFile() '将 intFile 设置为未使用的文件
' OpenURL 方法的结果首先传入 Byte 数组,
'然后将 Byte 数组保存到磁盘。
On Error Resume Next
Kill localfile
On Error GoTo 0
bData() = Inet1.OpenURL(UrtFile, icByteArray)
c = Inet1.GetHeader()
h = Split(c, vbCrLf)
If InStr(1, h(0), "HTTP/1.1 404", vbTextCompare) Then
MsgBox "在该分辨率下找不到卫星图片!"
ElseIf InStr(1, h(0), "HTTP/1.1 200 OK", vbTextCompare) Then
Open localfile For Binary Access Write As #intfile
Put #intfile, , bData()
Close #intfile
End If
Exit Sub
err1:
MsgBox "error!"
Resume
End Sub
Private Sub cmdCreate_Click()
DoRebuild
End Sub