Function 高德货车里程(d1 As String, d2 As String)
'第一步:抓取网页源代码(JSON格式)
Dim x As MSXML2.XMLHTTP60
Set x = New MSXML2.ServerXMLHTTP60
With x
.Open "GET", "https://restapi.amap.com/v4/direction/truck?width=2.5&strategy=10&size=2&weight=1.5&axis=2&origin=" & d1 & "&destination=" & d2 & "&height=1.6&nosteps=1&load=0.9&key=<用户的KEY>", False
'.setRequestHeader
.send
Dim sc As String
sc = x.responseText
' Debug.Print sc
End With
'第二步:根据文本格式特点,提取想要的数。因未学会解析JSON格式数据,暂不采用解析JSON格式
Dim a, b, c As Integer
Dim s As String
a = InStr(sc, "distance") + 10 '距离字段开始位置
b = InStr(sc, "duration") - 2 '距离字段结算位置
c = b - a '距离字段长度
高德货车里程 = Mid(sc, a, c)
' Debug.Print s
End Function
09-28
03-12