首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在VBA中使用Google Maps API进行地理定位

在VBA中使用Google Maps API进行地理定位
EN

Stack Overflow用户
提问于 2012-11-16 21:09:42
回答 2查看 1.8K关注 0票数 1

因此,我正要在VBA中完成我的地理编码脚本,但在beta测试期间,我注意到它无法提取大多数地址的数据,而对于其他地址,它工作得很好。代码如下:

代码语言:javascript
复制
Sub newReadXMLData(link As String)
Dim odc As DOMDocument
Dim lat As String
Dim lng As String
Dim location As IXMLDOMElement
Dim locationPath As String
Dim i As Integer

Set odc = New MSXML2.DOMDocument
odc.async = False
odc.Load (link)

locationPath = "GeocodeResponse/result/geometry[location_type='ROOFTOP']/location"
Set location = odc.SelectSingleNode(locationPath)

lat = GetTextValue(location, "./lat")
lng = GetTextValue(location, "./lng")

Debug.Print lat & "; " & lng

End Sub

Function GetTextValue(node As IXMLDOMElement, Optional xpath As String = "") As String
  Dim selectedNode As IXMLDOMElement

  If xpath <> "" And Not node Is Nothing Then
    Set selectedNode = node.SelectSingleNode(xpath)
  Else
    Set selectedNode = node
  End If

  If selectedNode Is Nothing Then
    GetTextValue = ""
  Else
    GetTextValue = Trim(selectedNode.Text)
  End If
End Function

该脚本返回正确的值,例如http://maps.googleapis.com/maps/api/geocode/xml?address=1+Infinite+Loop,+Cupertino,+Santa+Clara,+California+95014&sensor=false,但不返回任何值,例如http://maps.googleapis.com/maps/api/geocode/xml?address=BAGIENNA+13,+88-100+INOWROCŁAW&sensor=false。谁能解释一下这是为什么?

EN

回答 2

Stack Overflow用户

发布于 2012-11-17 17:43:18

我想可能是编码错误。我让您的两个字符串在浏览器中都能正常工作,但是当我尝试您的VBA代码时,第二个字符串返回ZERO_RESULTS。INOWROCŁAW中有一个字符在VBA中似乎不起作用(我在Word 2010中尝试过)。

票数 2
EN

Stack Overflow用户

发布于 2012-11-17 00:16:06

似乎Olle Sjögren是对的--这个问题是由地址中的特殊字符引起的。一个简单的字符转换函数就可以完成这项工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13417285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档