3
1

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 5 years have passed since last update.

GoでOpen Location Code (plus+codes) を扱う

Last updated at Posted at 2019-01-07

Open Location Code (OLC) をGoから使用するのが簡単だったのでメモしておきます。

Open Location Code (OLC) とは

Googleが策定・開発した、座標(緯度・経度)を一意の(短い)文字列に変換するコードです。Google Mapsなどではplus+Codesと呼称されています。

たとえば慶應義塾大学三田キャンパス(35.648703, 139.742884)は8Q7XJPXV+F5と表記されます。

OLC自体の詳細や仕様については以下のサイトをご覧ください

下準備

go get する。

$ go get github.com/google/open-location-code/go

使う

こういう感じです。

package main

import (
	"fmt"
	"github.com/google/open-location-code/go"
)

func main() {
	//Encode (座標→OLC)
	olcGridName := olc.Encode(35.7720007, 139.7472105, 10) //緯度(float64),経度(float64),OLCの桁数(int)
	fmt.Println(olcGridName)
	//Decode(OLC→座標)
	area, _ := olc.Decode("8Q7XJPXV+F5")
	fmt.Println(area)
}

実行結果はこのようになります。Encodeはその座標が含まれるグリッドが示されますが、Decodeではグリッドの範囲(左下の座標と右上の座標)と渡されたOLCの桁数が示されます。

8Q7XJPXV+F5
{35.648624999999996 139.74287500000003 35.64874999999999 139.74300000000005 10}

公式ドキュメント

詳細は公式ドキュメントをご覧ください。

3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?