Last active
May 7, 2018 02:42
-
-
Save testpilot031/681aad4944049f04077c03d26b79a4bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Function getDistance(latA As String, lonA As String, latB As String, lonB As String) As String | |
'--------------------------------- | |
' Example of Creating Function to WebAPI | |
' - Excel 2013 | |
' Add 'Microsoft XML, V 6.0' by reference setting | |
' | |
' Ask the Geographical Survey Institute Web API to get a distance between two points | |
' 参考:距離と方位角の計算(入力パラメータ)https://vldb.gsi.go.jp/sokuchi/surveycalc/api_help.html | |
' | |
' Usage:MsgBox ("Distance is " & getDistance(33.584818, 130.40786, 33.591333, 130.40113) & " m") | |
'--------------------------------- | |
Dim baseURL As String | |
Dim param As String | |
baseURL = "https://vldb.gsi.go.jp/sokuchi/surveycalc/surveycalc/bl2st_calc.pl?" | |
param = "outputType=xml&ellipsoid=bessel" _ | |
& "&latitude1=" & latA _ | |
& "&longitude1=" & lonA _ | |
& "&latitude2=" & latB _ | |
& "&longitude2=" & lonB | |
Dim httpReq As XMLHTTP60 | |
Dim XMLDocument As MSXML2.DOMDocument | |
Set httpReq = New XMLHTTP60 | |
httpReq.Open "GET", baseURL & param | |
httpReq.Send | |
Do While httpReq.readyState < 4 | |
DoEvents | |
Loop | |
'Debug.Print httpReq.responseText | |
Dim xmlDate As IXMLDOMNode | |
If httpReq.Status = 200 Then | |
' COMMUNICATION SUCCESS | |
Set XMLDocument = httpReq.responseXML | |
Set xmlDate = XMLDocument.SelectSingleNode("//ExportData/OutputData/geoLength") | |
getDistance = xmlDate.Text | |
Else | |
getDistance = "COMMUNICATION ERROR" | |
End If | |
Set httpReq = Nothing | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment