Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps 谷歌地图方向只_Google Maps_Excel_Excel 2010_Vba - Fatal编程技术网

Google maps 谷歌地图方向只

Google maps 谷歌地图方向只,google-maps,excel,excel-2010,vba,Google Maps,Excel,Excel 2010,Vba,我正在做一个项目,我想在excel工作表的WebBrowser对象中显示google地图。我已经使用这个URL完成了这项工作 我还想只显示同一链接(或不同链接)的行驶方向 我找不到任何关于如何让谷歌地图只通过URL返回方向的信息 阿希亚, LarryR您可能想查看谷歌地图Api: 这些API为您提供了XML响应,您可以在其中解析它们以显示结果。 我制作了一个用于查找时间和距离的示例: 这是我之前的一次尝试,因此没有使用XML,但它将让您了解如何处理来自google的响应 Public Fu

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

我还想只显示同一链接(或不同链接)的行驶方向

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

阿希亚,
LarryR

您可能想查看谷歌地图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
公共函数GMap(源地址为字符串,目标地址为字符串,可选模式为整数=1,可选数据类型为整数=1)
作为字符串的Dim surl
作为对象的Dim-oXH
作为字符串的文本
暗时间作为字符串
作为字符串的暗距离
作为字符串的Dim strmode
如果模式=1,则
strmode=“步行”
ElseIf模式=2,然后
strmode=“驾驶”
ElseIf模式=3,然后
strmode=“骑自行车”
其他的
GMap=“无效模式”
退出功能
如果结束
苏尔=”http://maps.googleapis.com/maps/api/distancematrix/xml?origins=;" & _
替换(源地址“,”+”&“&destinations=”&Replace(目的地址“,”+”&)_
“&mode=“&strmode&&sensor=false&units=metric”
设置oXH=CreateObject(“msxml2.xmlhttp”)
含氧
.打开“get”,surl,False
.发送
bodytxt=.responseText
以
bodytxt=右(bodytxt,Len(bodytxt)-InStr(1,bodytxt,“”)-5)
tim_e=左(bodytxt,InStr(1,bodytxt,“”)-1)
bodytxt=右(bodytxt,Len(bodytxt)-InStr(1,bodytxt,“”)-5)
distanc_e=左(bodytxt,InStr(1,bodytxt,“”)-1)
如果数据类型=1,则
GMap=CDbl(替换为“分钟”)
ElseIf数据类型=2,则
GMap=CDbl(替换(距离,公里)
其他的
GMap=“无效数据”
如果结束
设置oXH=无
端函数

我有一个Excel加载项,可以满足您的要求: