LoginSignup
0
3

More than 5 years have passed since last update.

Google MapのURLから緯度、経度を抜き出しさらにDMS( 度分秒)形式にする関数

Last updated at Posted at 2018-04-22

Access Excel 緯度 経度 130度45分15.001秒 S20度22分30秒を130.000 -20.0000に変換する関数

というのをやりましたので、こんどはGoogle MapのURLから緯度経度を取り出します。
ところで緯度(latitude)と経度(longitude)の覚え方。
Longitude の略し方。lng 派と lon 派の終わらない争い
というのがあったみたいですね。
とりあえず略さない方向で行きます。
しかし重要なのは表示方法の名前です。
GISで使う経緯度の基礎知識とかTIPSとか

度分秒(DMS): 41°24'12.2"N 2°10'26.5"E ただし漢字表記にします
度分(DMM): 41 24.2028, 2 10.4418
度(DD): 41.40338, 2.17403

緯度と経度の確認、入力

上部の検索ボックスに座標を入力します。使用できる形式は次のとおりです。
度分秒(DMS): 41°24'12.2"N 2°10'26.5"E
度分(DMM): 41 24.2028, 2 10.4418
度(DD): 41.40338, 2.17403

ここでもまた増毛駅を例にしてみよう。ランドマークとして記録され、ユニークで、広いところに1か所だけある。
地図はQiitaでるかな。

<iframe src="https://www.google.com/maps/embed?pb" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>

出ないですね...
https://goo.gl/maps/AGBRVc2EsYT2
https://goo.gl/maps/AGBRVc2EsYT2

GoogleのURLは主流はDD形式

https://www.google.com/maps/place/増毛駅/@43.8572216,141.5249246,17z/data=!3m1!4b1!4m5!3m4!1s0x5f0c7a957115429f:0x6632aaac1fab4098!8m2!3d43.8572178!4d141.5271133?hl=ja
増毛駅のところはDMS形式の緯度経度に変わったりする。変わらないのは@以下のDD形式。
ここを正規表現で取り出し、緯度経度をコンマで区切り、返す関数を作る。
漢字にするのは、その方があとでDD形式に変換するとき正規表現で切りやすいからです。
見た目でもわかりやすいですし。


Function RtnLatitudeLonditudeDMSfromGmapURL(sURL As String) As String
Dim Rex: Set Rex = CreateObject("Vbscript.regExp")
Dim MC, M
Dim ar
Dim lgDgree As Long, dbMinutes As Double, dbSec As Double
Dim dbLongitude As Double, dbLatitude As Double, strLongitude As String, strLatitude As String
With Rex
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = ".[0-9]{1,3}\.[0-9]{0,},.[0-9]{1,3}\.[0-9]{0,}\b"
If .test(sURL) = True Then
Set MC = .Execute(sURL)
ar = Split(Replace(MC.Item(0), "@", "", 1, 1, vbTextCompare), ",")
dbLatitude = ar(0)
lgDgree = Fix(ar(0))
dbMinutes = Fix((Abs(ar(0)) - Abs(lgDgree)) * 60)
dbSec = Int((Abs(ar(0)) - Abs(lgDgree) - (dbMinutes / 60)) * 3600 * (10 ^ 5)) / (10 ^ 5)
strLatitude = lgDgree & "度" & dbMinutes & "分" & dbSec & "秒"
dbLongitude = ar(1)
lgDgree = Fix(ar(1))
dbMinutes = Fix((Abs(ar(1)) - Abs(lgDgree)) * 60)
dbSec = Int((Abs(ar(1)) - Abs(lgDgree) - (dbMinutes / 60)) * 3600 * (10 ^ 5)) / (10 ^ 5)
strLongitude = lgDgree & "度" & dbMinutes & "分" & dbSec & "秒"
RtnLatitudeLonditudeDMSfromGmapURL = strLatitude & "," & strLongitude
Else
RtnLatitudeLonditudeDMSfromGmapURL = ""
End If
End With
End Function

DD形式も


Function RtnLatitudeLonditudeDDfromGmapURL(sURL As String) As String
Dim Rex: Set Rex = CreateObject("Vbscript.regExp")
Dim MC, M
Dim ar
With Rex
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = ".[0-9]{1,3}\.[0-9]{0,},.[0-9]{1,3}\.[0-9]{0,}\b"
If .test(sURL) = True Then
Set MC = .Execute(sURL)
ar = Split(Replace(MC.Item(0), "@", "", 1, 1, vbTextCompare), ",")

RtnLatitudeLonditudeDDfromGmapURL = ar(0) & "," & ar(1)
Else
RtnLatitudeLonditudeDDfromGmapURL = ""
End If
End With
End Function

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3