Help us understand the problem. What is going on with this article?

【Kotlin】緯度経度変換器

More than 1 year has passed since last update.

はじめに

Exifで取得した緯度経度をGoogleMapApiとかで使いたい時に変換調べるの面倒なのでまとめておきます。

['35/1', '48/1', '986/100'] みたいな文字列型を (35 / 1) + (48 / 1 / 60) + (986 / 100 / 3600) してDouble型で返します。

参考: 画像ファイルのEXIFタグから撮影日時と位置情報を取得する際のTips

サンプル

fun LngLatConverter(origin:String):Double{
        val origins=origin.split(Regex(","),0)
        val freq=origins[0]
        val freqs=freq.split(Regex("/"),0)
        val min=origins[1]
        val mins=min.split(Regex("/"),0)
        val sec=origins[2]
        val secs=sec.split(Regex("/"),0)

        val reFreq=freqs[0].toDouble()/freqs[1].toDouble()
        val reMin=mins[0].toDouble()/mins[1].toDouble()/60
        val reSec=secs[0].toDouble()/secs[1].toDouble()/3600

        return reFreq+reMin+reSec
    }

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away