0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

度分秒(DMS)表記を十進数(Decimal)に変換する雑なやり方

Last updated at Posted at 2021-09-14

[追記] もっと簡潔に書ける方法を教えてもらったので、コメント欄を参照してください。


"北緯35度39分31秒 東経139度44分44秒""35°39′31″N 139°44′44″E"などの表記を十進数表記に雑に変換する。

function dms2decimal(dms) {    
    return dms.split(/\D/).filter(d => d != "").reduce((a, c, i) => {
        const opt = {
            1: 60,
            2: 3600
        }
        const na = +a;
        const nc = +c;
        return na + (nc / opt[i])
    })
}
> dms2decimal("北緯35度39分31秒");
<- 35.65861111111111

> dms2decimal("東経139度44分44");
<- 139.74555555555554

> dms2decimal("35°39′31″N");
<- 35.65861111111111

> dms2decimal("139°44′44″E");
<- 139.74555555555554

実に雑なので、誤作動するときがあるかも。

0
0
3

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?