21. Function reverseGeocoding( lat As Double, lng As Double ) As String
Dim ss As New NotesSession
Dim req As NotesHTTPRequest
Dim nav As NotesJSONNavigator
Dim elm As NotesJSONElement
Dim arr As NotesJSONArray
Dim obj As NotesJSONObject
Dim url$
Const API_KEY = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" & lat & "," & lng & "&language=ja&key=" & API_KEY
Set req = ss.CreateHTTPRequest
req.PreferJSONNavigator = True
req.SetHeaderField "Content-Type", "application/json"
Set nav = req.Get( url )
Set elm = nav.GetElementByName( "results" )
Set arr = elm.Value
Set elm = arr.GetFirstElement
Set obj = elm.Value
Set elm = obj.GetElementByName( "formatted_address" )
reverseGeocoding = elm.Value
End Function
緯度と経度を入力して、住所を出力する
Google Maps API
戻り値から住所を抽出
24. 球面三角法
Function spherical_trigonometry( lat1 As Double, lng1 As Double, lat2 As Double, lng2 As Double ) As
Double
Dim radLat1 As Double, radLng1 As Double ‘地点1
Dim radLat2 As Double, radLng2 As Double ‘地点2
Dim averageLat As Double, averageLng As Double
Dim c As Double
Const r = 6378137.0 '赤道半径
c = 180 / Pi '1周を360とする60分法からラジアンへ変換する際に使用する。(360/2πを約分)
' 円弧の長さを扱うため、角度(緯度経度)をラジアンへ変換
radLat1 = lat1 / c
radLng1 = lng1 / c
radLat2 = lat2 / c
radLng2 = lng2 / c
averageLat = (radLat1 - radLat2) / 2
averageLng = (radLng1 - radLng2) / 2
spherical_trigonometry = r * 2 * Asin( Sqr( Sin( averageLat ) ^ 2 + Cos( radLat1 ) * Cos( radLat2 ) *
Sin( averageLng ) ^ 2 ) )
End Function
ヒュベニイ(Hubeny)の式
Function hubeny( lat1 As Double, lng1 As Double, lat2 As Double, lng2 As Double ) As Double
Dim dLat As Double, dLng As Double
Dim i As Double, W As Double, M As Double, N As Double
Const E2 = 6.69437999019758E-03 '第2離心率(e^2)
Const r = 6378137.0 '赤道半径
dLat = lat2 - lat1
dLng = lng2 - lng1
i = ( lat1 + lat2 ) / 2
W = Sqr( 1 - E2 * Sin( i * Pi / 180 ) ^ 2 )
M = r * ( 1 - E2 ) / W ^ 3
N = r * W
hubeny = Sqr( ( dLat * Pi / 180 * M ) ^ 2 + ( dLng * Pi / 180 * N * Cos( i * Pi / 180 ) ) ^ 2 )
End Function
25. Dim ss As New NotesSession
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim lat1 As Double, lng1 As Double
Dim lat2 As Double, lng2 As Double
Dim distance As Double
Set dc = ss.CurrentDatabase.UnprocessedDocuments
Set doc = dc.GetFirstDocument
lat1 = doc.GetItemValue("Latitude")(0)
lng1 = doc.GetItemValue("Longitude")(0)
Set doc = dc.GetNextDocument( doc )
lat2 = doc.GetItemValue("Latitude")(0)
lng2 = doc.GetItemValue("Longitude")(0)
distance = spherical_trigonometry(lat1, lng1, lat2, lng2)
Messagebox distance & " m",,"球面三角法による2地点間の距離"
ビューで選択している2つの
文書を取得し、それぞれに保
存されている位置情報から距
離を算出して表示する
28. Dim prefix$, suffix$, kml$
prefix = |<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>GPS LOG</name>
<description>KMLサンプル</description>
<Style id="blueLine">
<LineStyle>
<color>7fff00ff</color>
<width>4</width>
</LineStyle>
</Style>
<Placemark>
<name>GPS LOG</name>
<description>KML サンプル</description>
<styleUrl>#blueLine</styleUrl>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<altitudeMode>absolute</altitudeMode>
<coordinates>|
suffix = |</coordinates>
</LineString>
</Placemark>
</Document>
</kml>|
kml = prefix & root & suffix
Dim ss As New NotesSession
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim unid$
Set dc = ss.Currentdatabase.Unprocesseddocuments
Set doc = dc.Getfirstdocument()
unid = doc.Getitemvalue("unid")(0)
Set dc = Nothing
Set doc = Nothing
Dim vw As NotesView
Dim nav As NotesViewNavigator
Dim ent As NotesViewEntry
Dim root$
Set vw = ss.Currentdatabase.Getview( "byunid" )
Set nav = vw.Createviewnavfromcategory( unid )
Set ent = nav.Getfirst()
While Not ent Is Nothing
root = root & ent.Columnvalues( 2 ) & _
"," & ent.Columnvalues( 3 ) & _
"," & ent.Columnvalues( 4 ) & Chr(10)
Set ent = nav.Getnext( ent )
Wend
'KMLファイルを保存する
Dim filepath$, platform$, dlm$
Dim stream As NotesStream
platform = LCase( ss.Platform )
If platform = "ios" Then
dlm = "/"
ElseIf platform = "windows/32" Then
dlm = ""
End If
filepath = ss.Getenvironmentstring( "Directory", True )
filepath = filepath & dlm & "kml.kml"
Set stream = ss.Createstream()
If Not stream.Open( filepath, "UTF-8" ) Then
MessageBox "KMLファイルが開きません。",,"Open Failed"
Exit sub
End If
If stream.Bytes <> 0 Then
Call stream.Truncate()
End If
Call stream.Writetext( kml, EOL_CRLF )
Call stream.Close()
KMLファイルを作成する
ビューから取得した位置
情報(緯度、経度、高
度)をカンマで区切った1
行の文字列にして、複数
の位置情報を改行で区切
り、変数 root へ格納する
変数 kml の内容を
データディレクトリの
.kml ファイルへ書き出す
変数 root を 変数 prefix と
suffix で挟み、変数 kml へ
格納する