私のプロジェクトでは、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ファイルで特定のノードを選択する方法を誰かに説明してもらえますか?
- 別の解決策は、最初の座標セットのみを保持することです。