为什么我从web浏览器和Excel VBA获得的Google API place搜索结果不同?
我正在尝试使用GooglePlacesAPI从Excel电子表格中搜索位置,返回位置id、经度和纬度 当我将浏览器中的API与此URL一起使用时为什么我从web浏览器和Excel VBA获得的Google API place搜索结果不同?,excel,xml,vba,google-places-api,Excel,Xml,Vba,Google Places Api,我正在尝试使用GooglePlacesAPI从Excel电子表格中搜索位置,返回位置id、经度和纬度 当我将浏览器中的API与此URL一起使用时 https://maps.googleapis.com/maps/api/place/findplacefromtext/xml?key=MYKEY&input=%22saint%20mary,%20reading%20berkshire%22&inputtype=textquery&fields=place_id,geomet
https://maps.googleapis.com/maps/api/place/findplacefromtext/xml?key=MYKEY&input=%22saint%20mary,%20reading%20berkshire%22&inputtype=textquery&fields=place_id,geometry/location
我得到以下结果:
<FindPlaceFromTextResponse>
<candidates>
<geometry>
<location>
<lat>51.4544683</lat>
<lng>-0.9739627</lng>
</location>
</geometry>
<place_id>ChIJC-64rxabdkgRxjqxVE0q21k</place_id>
</candidates>
<status>OK</status>
</FindPlaceFromTextResponse>
实际上,这两个查询应该是相同的。我不明白他们为什么不这样做。欢迎使用帮助。您的strQuery在发送到谷歌服务之前是什么样子的。是否打开?我想知道它是否与URL编码有关?所以我实际上注释掉了URL编码函数,因为我也这么认为。它现在只是传递一个原始字符串作为输入。mary,阅读berkshire&inputtype=textquery&fields=place\u id,geometry/location如果我通过这个,我会得到同样的结果:我注意到你在评论中发布的链接与你的初始链接不太匹配。在您的输入中,它缺少前后引号的编码,逗号在一个与另一个之间编码。与你的评论相比,我更愿意尝试URL。看起来在URL中是否包含引号对于确定结果很重要。这大概是因为它不允许关键字的排列?
Function GMapsGeocode(address As Range) As Variant
'returns the Google place id, latitude and longitude
If myKey = "" Then myKey = InputBox("What's your Google API Key?")
Dim addressConcat As String: addressConcat = ConcatenateRow(address, " ")
Dim strAddress As String
Dim strQuery As String
'strAddress = URLEncode(addressConcat)
Dim Returns(2) As Variant
'Assemble the query string
strQuery = "https://maps.googleapis.com/maps/api/place/findplacefromtext/xml?"
strQuery = strQuery & "key=" & myKey
strQuery = strQuery & "&input=" & addressConcat
strQuery = strQuery & "&inputtype=textquery&fields=place_id,geometry/location"
'define XML and HTTP components
Dim googleResult As New MSXML2.DOMDocument
Dim googleService As New MSXML2.XMLHTTP
Dim firstResult As MSXML2.IXMLDOMNodeList
Dim oNodes As MSXML2.IXMLDOMNodeList
Dim oNode As MSXML2.IXMLDOMNode
googleService.Open "GET", strQuery, False
googleService.send
googleResult.LoadXML (googleService.responseText)