0

私のプロジェクトでは、GPS 座標を知りたい一連の場所をジオコーディングする必要があります。

場所の量は手動では大きすぎますが、多すぎないため、Geocoding API の使用に関する Google の制限に問題はありません。

私にとってこれを行う最も便利な方法は、OpenOffice Calc を使用することです。

必要なことだけを行うVBA コードを見つけました。

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="" src="http://s.w.org/images/core/emoji/72x72/1f609.png">
   URL = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=true&address="  'we will use the google maps api
   URL = URL & sSearch          'create the searchstring
   oSimpleFileAccess = createUnoService( "com.sun.star.ucb.SimpleFileAccess" ) 'this is the Sefvice in getting the data from the web
   On Error GoTo ErrorResponse
   oInputStream = oSimpleFileAccess.openFileRead(URL) 'use the URL
   oTextStream = createUnoService("com.sun.star.io.TextInputStream") 'get the data from the web
   oTextStream.InputStream = oInputStream 'this is the data
   aDelimiters = Array(ASC(">"),ASC("<")) 'as the stream is segmented with ">" and "<"
   sLastString = ""
   Do While NOT oTextStream.isEOF 'go through the google output
      sThisString = oTextStream.readString(aDelimiters,True) 
      Select Case sLastString 'now search for the entries
         Case "lat": 'latitudes
            sLat = sThisString  
            Case "lng": 'longitude
            sLon = sThisString
      End Select
      sLastString = sThisString
   Loop
   GetGeoData =  " Longitude: " & sLon & " Latitude: " &sLat 'this is our output in  the new cell
   oInputStream.closeInput()
   Exit Function
   ErrorResponse:
   GetGeoData = "no values found!!!"
End Function

ただし、正確な住所については問題ありませんが、Google がポリゴンとして認識している集落に関しては問題があります。この場合、コードは xml 情報で見つかった最後の座標セットのみを保持しますが、これはポリゴンの北東の角に対応します。Google マップによって生成された xml ドキュメントの最初の座標セットに対応する多角形の中心があれば幸いです。

  • このコードに基づいてxmlファイルで特定のノードを選択する方法を誰かに説明してもらえますか?
  • 別の解決策は、最初の座標セットのみを保持することです。
4

2 に答える 2

0

タグで「<」と「>」を一致させるだけでなく、より強力なものを探しているようです。これは、XML を操作するときによく発生し、このタスクを実行するための専用ライブラリが多数あります。

XML の解析は、com.sun.star.xml.sax.Parser インターフェイスを使用して OpenOffice Basic で実行できます。詳細については、 https://wiki.openoffice.org/wiki/XML_and_Filterを参照してください。

また、多くの言語には XML 解析ライブラリがあります。Java と Python には XML 解析ライブラリがあり、OpenOffice と連携することもできます。個人的に OpenOffice で最もよく使用するライブラリはxml.dom.minidomです。

于 2016-01-15T01:26:54.633 に答える