【问题标题】:Google Maps Directions Only仅限谷歌地图方向
【发布时间】:2013-07-21 22:28:20
【问题描述】:

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

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

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

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

AHIA, 拉里R

【问题讨论】:

    标签: google-maps excel excel-2010 vba


    【解决方案1】:

    您可能想查看 GoogleMaps Api:

    Static Map API

    Directions 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
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2013-08-20
        • 2011-07-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-02
        • 2011-11-11
        • 2011-09-07
        相关资源
        最近更新 更多