0

我正在做一个项目,我想在 Excel 工作表上的 WebBrowser 对象中显示谷歌地图。我已经使用这个 URL 完成了这个......

http://maps.google.com/?saddr=29.9390146,-90.0696139&daddr=29.962506,-90.1930133&f=d&output=embed

我还想仅显示同一链接(或不同链接)的行车路线。

我找不到任何关于如何让谷歌地图仅通过 URL 返回方向的信息。

AHIA,拉里

4

2 回答 2

1

您可能想查看 GoogleMaps Api:

静态地图 API

路线 API

这些 API 为您提供 XML 响应,您可以在其中解析它们以显示结果。我做了一个来查找时间和距离,您可以将其用作示例:这是我早期的尝试之一,因此没有使用 XML,但它会让您了解如何处理来自 google 的响应。

Public Function GMap(origin_address As String, destination_address As String, Optional mode As Integer = 1, Optional datatype As Integer = 1)

Dim surl As String
Dim oXH As Object
Dim bodytxt As String
Dim time_e As String
Dim distanc_e As String
Dim strmode As String

If mode = 1 Then
    strmode = "walking"
ElseIf mode = 2 Then
    strmode = "driving"
ElseIf mode = 3 Then
    strmode = "bicycling"
Else
    GMap = "Invalid Mode"
    Exit Function
End If

surl = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=;" & _
Replace(origin_address, " ", "+") & "&destinations=" & Replace(destination_address, " ", "+") & _
"&mode=" & strmode & "&sensor=false&units=metric"

Set oXH = CreateObject("msxml2.xmlhttp")

With oXH
    .Open "get", surl, False
    .send
    bodytxt = .responseText
End With

bodytxt = Right(bodytxt, Len(bodytxt) - InStr(1, bodytxt, "<text>") - 5)
tim_e = Left(bodytxt, InStr(1, bodytxt, "</text>") - 1)
bodytxt = Right(bodytxt, Len(bodytxt) - InStr(1, bodytxt, "<text>") - 5)
distanc_e = Left(bodytxt, InStr(1, bodytxt, "</text>") - 1)

If datatype = 1 Then
    GMap = CDbl(Replace(tim_e, "mins", ""))
ElseIf datatype = 2 Then
    GMap = CDbl(Replace(distanc_e, "km", ""))
Else
    GMap = "Invalid Data"
End If

Set oXH = Nothing
End Function
于 2013-07-22T18:34:53.607 回答
0

我有一个 Excel 插件可以满足您的要求: http: //www.calvert.ch/geodesix/

于 2014-03-31T20:43:54.310 回答