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 Excel VBA地理编码响应无效_Google Maps_Vba_Geocoding - Fatal编程技术网

Google maps Excel VBA地理编码响应无效

Google maps Excel VBA地理编码响应无效,google-maps,vba,geocoding,Google Maps,Vba,Geocoding,我使用此脚本获取德国任何地址的地理代码: Public Function getGoogleMapsGeocode(sAddr As String) As String Dim xhrRequest As XMLHTTP60 Dim sQuery As String Dim domResponse As DOMDocument60 Dim ixnStatus As IXMLDOMNode Dim ixnLat As IXMLDOMNode Dim ixnLng As IXMLDOMNode

我使用此脚本获取德国任何地址的地理代码:

Public Function getGoogleMapsGeocode(sAddr As String) As String

Dim xhrRequest As XMLHTTP60
Dim sQuery As String
Dim domResponse As DOMDocument60
Dim ixnStatus As IXMLDOMNode
Dim ixnLat As IXMLDOMNode
Dim ixnLng As IXMLDOMNode


' Use the empty string to indicate failure
getGoogleMapsGeocode = ""

Set xhrRequest = New XMLHTTP60
sQuery = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address="
sQuery = sQuery & Replace(sAddr, " ", "+")
xhrRequest.Open "GET", sQuery, True
xhrRequest.send

Set domResponse = New DOMDocument60
domResponse.LoadXML xhrRequest.responseText
Set ixnStatus = domResponse.SelectSingleNode("//status")

If (ixnStatus.Text <> "OK") Then
    'Exit Function
End If

Set ixnLat = domResponse.SelectSingleNode("/GeocodeResponse/result/geometry/location/lat")
Set ixnLng = domResponse.SelectSingleNode("/GeocodeResponse/result/geometry/location/lng")

getGoogleMapsGeocode = ixnLat.Text & ", " & ixnLng.Text

End Function
当我在浏览器中键入查询字符串时,它将返回一个带有地理代码的有效xml响应。如果我让vba来做,我会得到一个错误。有什么我应该知道的吗

答复正文:

 "<?xml version="1.0" encoding="UTF-8"?>
<GeocodeResponse>
 <status>INVALID_REQUEST</status>
</GeocodeResponse>
" : String : Modul8.getGoogleMapsGeocode

它对我来说没有错误。函数或请求只是在浏览器中?我将你的函数粘贴到一个标准模块中,添加了对Microsoft XML 6.0的引用,当我输入地址时,我得到了坐标。它没有在responsetext上出错,因为它尚未完成加载。好吧,我撒了谎,我只犯了一个错误。但我进行了调试,然后F5继续运行,到那时xml已经加载。我没有收到无效的请求。