21
21

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.

ipから都市情報を取得する

Last updated at Posted at 2015-07-31

が良さそうです。

install

$ brew install go
$ go get github.com/fiorix/freegeoip
$ go get github.com/fiorix/freegeoip/cmd/freegeoip

※golangのその他の設定はしておいてね

Usage

サーバーを起動

$ freegeoip

叩いてみる

$ curl  http://localhost:8080/json/hatena.com | jq .
{
  "ip": "59.106.194.50",
  "country_code": "JP",
  "country_name": "Japan",
  "region_code": "27",
  "region_name": "Ōsaka",
  "city": "Osaka",
  "zip_code": "540-0008",
  "time_zone": "Asia/Tokyo",
  "latitude": 34.6864,
  "longitude": 135.52,
  "metro_code": 0
}

$ curl  http://localhost:8080/json/qiita.com | jq .
{
  "ip": "54.248.79.191",
  "country_code": "JP",
  "country_name": "Japan",
  "region_code": "13",
  "region_name": "Tōkyō",
  "city": "Tokyo",
  "zip_code": "100-0001",
  "time_zone": "Asia/Tokyo"
  "latitude": 35.685,
  "longitude": 139.7514,
  "metro_code": 0
}

※ jq入ってないならbrew install jq

都市レベルでわかります!すごい!便利!

21
21
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
21
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?