Google maps OpenOffice Calc VBA中的Google地图地理编码API

Google maps OpenOffice Calc VBA中的Google地图地理编码API,google-maps,geocoding,openoffice-calc,openoffice-basic,Google Maps,Geocoding,Openoffice Calc,Openoffice Basic,对于我的项目,我需要对一组我想知道GPS坐标的位置进行地理编码 它的位置数量太大,无法手动添加,但不会太多,这样我就不会对谷歌使用地理编码API的局限性产生问题 对我来说,最方便的方法是使用OpenOfficeCalc 我找到了一个能满足我需要的: Function GetGeoData(sSearch as String) as String If Len(sSearch) = 0 Then Exit Function 'we dont need empty cells <img

对于我的项目,我需要对一组我想知道GPS坐标的位置进行地理编码

它的位置数量太大,无法手动添加,但不会太多,这样我就不会对谷歌使用地理编码API的局限性产生问题

对我来说,最方便的方法是使用OpenOfficeCalc

我找到了一个能满足我需要的:

Function GetGeoData(sSearch as String) as String
   If Len(sSearch) = 0 Then Exit Function 'we dont need empty cells <img draggable="false" class="emoji" alt="It sounds like you are looking for something more powerful than just matching "<" and ">" in tags.  This often happens when working with XML, and there are many specialized libraries to accomplish this task.

Parsing XML can be accomplished in OpenOffice Basic using the com.sun.star.xml.sax.Parser interface. See https://wiki.openoffice.org/wiki/XML_and_Filter for details.

Alternatively, many languages have XML parsing libraries. Java and Python have XML parsing libraries and can also work with OpenOffice. The library I personally use most with OpenOffice is xml.dom.minidom.

At first: Never take
XML
as text string only.
XML
has a meaningful data structure which needs to be parsed. Fortunately the Openoffice API provides a
XML
parser already.
com.sun.star.xml.dom.DocumentBuilder
https://www.openoffice.org/api/docs/common/ref/com/sun/star/xml/dom/DocumentBuilder.html

To your question: Each
result
has a
geometry
with a
location
. The
lat
,
lng
in that
location
will be either the approximate
lat
,
lng
or the geometric center. The other
lat
,
lng
are viewport or bounds ones.

Example Berlin, Germany:

  <geometry>
   <location>
    <lat>52.5200066</lat>
    <lng>13.4049540</lng>
   </location>
   <location_type>APPROXIMATE</location_type>
   <viewport>
    <southwest>
     <lat>52.3396296</lat>
     <lng>13.0891553</lng>
    </southwest>
    <northeast>
     <lat>52.6754542</lat>
     <lng>13.7611176</lng>
    </northeast>
   </viewport>
   <bounds>
    <southwest>
     <lat>52.3396296</lat>
     <lng>13.0891553</lng>
    </southwest>
    <northeast>
     <lat>52.6754542</lat>
     <lng>13.7611176</lng>
    </northeast>
   </bounds>
  </geometry>
函数GetGeoData(sSearch作为字符串)作为字符串

如果Len(sSearch)=0,则退出函数“我们不需要空单元格”听起来您正在寻找比标记中的“”匹配功能更强大的功能。这通常发生在使用XML时,有许多专门的库来完成这项任务

可以使用com.sun.star.XML.sax.Parser接口在OpenOffice Basic中完成XML解析。有关详细信息,请参阅


或者,许多语言都有XML解析库。Java和Python有XML解析库,也可以与OpenOffice一起使用。我个人在OpenOffice中使用最多的库是。

听起来您正在寻找比在标记中匹配“”更强大的库。这通常发生在使用XML时,有许多专门的库来完成这项任务

可以使用com.sun.star.XML.sax.Parser接口在OpenOffice Basic中完成XML解析。有关详细信息,请参阅


或者,许多语言都有XML解析库。Java和Python有XML解析库,也可以与OpenOffice一起使用。我个人在OpenOffice中使用最多的库是。

首先:永远不要将
XML
仅作为文本字符串
XML
具有需要解析的有意义的数据结构。幸运的是,Openoffice API已经提供了
XML
解析器
com.sun.star.xml.dom.DocumentBuilder

针对您的问题:每个
结果
都有一个
几何体
和一个
位置
。该
位置的
lat
lng
将是近似
lat
lng
或几何中心。另一个
lat
lng
是视口或边界

例如德国柏林:

Function GetGeoData(sSearch as String) as String

 sResult = ""

 if len(sSearch) > 0 and sSearch <> "0" then

  sURI = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=true&address="
  sURI = sURI & sSearch
  oDocumentBuilder = createUnoService("com.sun.star.xml.dom.DocumentBuilder")
  oDOMDocument = oDocumentBuilder.parseURI(sURI)

  oResults = oDOMDocument.getElementsByTagName("result")

  for i = 0 to oResults.length -1
   oResult = oResults.item(i)
   oformattedAddress = oResult.getElementsByTagName("formatted_address").item(0)
   sformattedAddress = oformattedAddress.getFirstChild().nodeValue

   oGeometry = oResult.getElementsByTagName("geometry").item(0)
   oLocation = oGeometry.getElementsByTagName("location").item(0)
   oLat = oLocation.getElementsByTagName("lat").item(0)
   sLat = oLat.getFirstChild().nodeValue
   oLng = oLocation.getElementsByTagName("lng").item(0)
   sLng = oLng.getFirstChild().nodeValue

   if i = 0 then 
    sResult = sResult & sformattedAddress & ": Lat:" & sLat & " Lng:" & sLng
   else
    sResult = sResult & "; " & sformattedAddress & ": Lat:" & sLat & " Lng:" & sLng    
   end if   

  next

 end if

 GetGeoData = sResult

End Function

首先:不要将
XML
仅作为文本字符串
XML
具有需要解析的有意义的数据结构。幸运的是,Openoffice API已经提供了
XML
解析器
com.sun.star.xml.dom.DocumentBuilder

针对您的问题:每个
结果
都有一个
几何体
和一个
位置
。该
位置的
lat
lng
将是近似
lat
lng
或几何中心。另一个
lat
lng
是视口或边界

例如德国柏林:

Function GetGeoData(sSearch as String) as String

 sResult = ""

 if len(sSearch) > 0 and sSearch <> "0" then

  sURI = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=true&address="
  sURI = sURI & sSearch
  oDocumentBuilder = createUnoService("com.sun.star.xml.dom.DocumentBuilder")
  oDOMDocument = oDocumentBuilder.parseURI(sURI)

  oResults = oDOMDocument.getElementsByTagName("result")

  for i = 0 to oResults.length -1
   oResult = oResults.item(i)
   oformattedAddress = oResult.getElementsByTagName("formatted_address").item(0)
   sformattedAddress = oformattedAddress.getFirstChild().nodeValue

   oGeometry = oResult.getElementsByTagName("geometry").item(0)
   oLocation = oGeometry.getElementsByTagName("location").item(0)
   oLat = oLocation.getElementsByTagName("lat").item(0)
   sLat = oLat.getFirstChild().nodeValue
   oLng = oLocation.getElementsByTagName("lng").item(0)
   sLng = oLng.getFirstChild().nodeValue

   if i = 0 then 
    sResult = sResult & sformattedAddress & ": Lat:" & sLat & " Lng:" & sLng
   else
    sResult = sResult & "; " & sformattedAddress & ": Lat:" & sLat & " Lng:" & sLng    
   end if   

  next

 end if

 GetGeoData = sResult

End Function

这可能有助于为“谷歌称为多边形的结算”提供一个
sSearch
参数示例。此外,标签(和标题)应为
openoffice basic
,而不是仅适用于MS Office的
vba
。为了避免交叉发布,我建议将其从gis.stackexchange.com中删除,因为您确实只需要帮助正确解析XML文件。这可能有助于为“谷歌称为多边形的结算”提供一个
sSearch
参数示例。标签(和标题)也应该是
openoffice basic
,而不是仅适用于MS Office的vba。为了避免交叉发布,我建议将其从gis.stackexchange.com中删除,因为您实际上只需要帮助正确解析XML文件。