ただし、ツイート (つぶやき, status) から取得できる位置情報に限る (プロフィールの位置情報は今回扱わない)。

ツイートは Twitter API の


http://api.twitter.com/1/statuses/user_timeline.json?screen_name=nilab&trim_user=true

にて取得している。

Ref. GET statuses/user_timeline | Twitter Developers

ツイートから取得できる位置情報は3種類

ツイート (APIリファレンスによるとstatusと呼ばれる) に含まれる位置情報は以下の3種類。

  • coordinates: 経度・緯度
  • geo: 緯度・経度
  • place: Twitterが管理する場所データベースのエントリ

coordinates オブジェクト

coordinates に経度、緯度の順番 (GeoJSON形式) で位置情報が格納されている。


"coordinates": {
  "type": "Point",
  "coordinates": [
    136.88562512,
    35.17593059
  ]
}

geo オブジェクト

緯度、経度 (前述のcoordinatesオブジェクトとは逆の順番) の順番で位置情報が格納されている。


"geo": {
  "type": "Point",
  "coordinates": [
    35.17593059,
    136.88562512
  ]
}

place オブジェクト

Twitterが管理する場所データベースのエントリが格納されている。
複数の経度・緯度を持つポリゴン形状となっていて、場所の名称や属する国の情報なども含まれている。


"place": {
  "name": "Nagoya City Nishi Ward",
  "country_code": "JP",
  "attributes": {},
  "full_name": "Nagoya City Nishi Ward, Aichi",
  "url": "http://api.twitter.com/1/geo/id/6169466efdfafa79.json",
  "bounding_box": {
    "type": "Polygon",
    "coordinates": [
      [
        [
          136.855966666667,
          35.1709238888889
        ],
        [
          136.908068888889,
          35.1709238888889
        ],
        [
          136.908068888889,
          35.2345627777778
        ],
        [
          136.855966666667,
          35.2345627777778
        ]
      ]
    ]
  },
  "place_type": "city",
  "country": "Japan",
  "id": "6169466efdfafa79"
}

coordinates と geo の値が同じ

自分がいままで見たデータの中には、coordinates オブジェクトと geo オブジェクトの値は緯度と経度の順序が違うだけで、中身は同じものしか見つからなかった。

勝手な推測をするなら、もしかして Twitter API には geo オブジェクトが先に存在していてこれはGeoJSONのフォーマットで規定されている緯度・経度の順序と異なるため、順序を変更しただけの coordinates オブジェクトを用意したのではないだろうか。互換性のため geo オブジェクトはそのままで。

いろいろなクライアントで投稿した位置情報付きツイートの状況

Twitter クライアントcoordinates の有無geo の有無place の有無
PC + twitter.com (サイト)××
iPhone + mobile.twitter.com (サイト)
iPhone + Echofon (アプリ)××
iPhone + foursquare (アプリ)
iPhone + nilogger (自作アプリ)

nilogger (自作 iPhone アプリ) ではツイートする際に lat, long パラメータを付加して投稿している。調査した結果からすると、 lat, long は coordinates, geo オブジェクトにセットされ、それだけでなく place オブジェクトにも Twitter サイト側で自動的に情報がセットされるようだ。

以下に、それぞれのクライアントによる位置情報付きツイート(status)のJSONデータを列挙する。

PC + twitter.com (サイト)

 coordinatesgeoplace
PC + twitter.com (サイト)××

{
  "in_reply_to_screen_name": null,
  "place": {
    "name": "Nagoya City Naka Ward",
    "country_code": "JP",
    "attributes": {},
    "full_name": "Nagoya City Naka Ward, Aichi",
    "url": "http://api.twitter.com/1/geo/id/b65f8a1a90e649ad.json",
    "bounding_box": {
      "type": "Polygon",
      "coordinates": [
        [
          [
            136.891989166667,
            35.1426647222222
          ],
          [
            136.929841666667,
            35.1426647222222
          ],
          [
            136.929841666667,
            35.1872666666667
          ],
          [
            136.891989166667,
            35.1872666666667
          ]
        ]
      ]
    },
    "place_type": "city",
    "country": "Japan",
    "id": "b65f8a1a90e649ad"
  },
  "favorited": false,
  "id_str": "183017400109776898",
  "geo": null,
  "user": {
    "id_str": "5704532",
    "id": 5704532
  },
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "retweet_count": 0,
  "retweeted": false,
  "truncated": false,
  "in_reply_to_user_id_str": null,
  "coordinates": null,
  "source": "web",
  "created_at": "Fri Mar 23 02:28:43 +0000 2012",
  "contributors": null,
  "id": 183017400109776900,
  "in_reply_to_user_id": null,
  "text": "名古屋市中区みたいな。"
}

placeオブジェクトの経度緯度ポリゴンを地図上に展開するとこんな感じ。
PC + twitter.com (サイト)

PC + twitter.com (サイト)
Twitter / @nilab: 名古屋市中区みたいな。 ...

ツイートの「from Nagoya City Naka Ward, Aichi」のところが https://twitter.com/#!/places/b65f8a1a90e649ad へのリンクになっていて、そのまま、

Nagoya City Naka Ward, Aichi, Japan - Google マップ へリダイレクトされる。
PC + twitter.com (サイト)

iPhone 4S + mobile.twitter.com (サイト)

 coordinatesgeoplace
iPhone + mobile.twitter.com (サイト)

{
  "in_reply_to_screen_name": null,
  "place": {
    "name": "Nagoya City Nishi Ward",
    "country_code": "JP",
    "attributes": {},
    "full_name": "Nagoya City Nishi Ward, Aichi",
    "url": "http://api.twitter.com/1/geo/id/6169466efdfafa79.json",
    "bounding_box": {
      "type": "Polygon",
      "coordinates": [
        [
          [
            136.855966666667,
            35.1709238888889
          ],
          [
            136.908068888889,
            35.1709238888889
          ],
          [
            136.908068888889,
            35.2345627777778
          ],
          [
            136.855966666667,
            35.2345627777778
          ]
        ]
      ]
    },
    "place_type": "city",
    "country": "Japan",
    "id": "6169466efdfafa79"
  },
  "favorited": false,
  "id_str": "183026841001537537",
  "geo": {
    "type": "Point",
    "coordinates": [
      35.17521286,
      136.88532751
    ]
  },
  "user": {
    "id_str": "5704532",
    "id": 5704532
  },
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "retweet_count": 0,
  "retweeted": false,
  "truncated": false,
  "in_reply_to_user_id_str": null,
  "coordinates": {
    "type": "Point",
    "coordinates": [
      136.88532751,
      35.17521286
    ]
  },
  "source": "<a href=\"http://mobile.twitter.com\" rel=\"nofollow\">Mobile Web</a>",
  "created_at": "Fri Mar 23 03:06:14 +0000 2012",
  "contributors": null,
  "id": 183026841001537540,
  "in_reply_to_user_id": null,
  "text": "おなかすいた"
}

placeオブジェクトの経度緯度ポリゴンとcoordinates/geoオブジェクトをアイコンとして地図上に展開するとこんな感じ。
iPhone + mobile.twitter.com (サイト)

iPhone + mobile.twitter.com (サイト)
Twitter / @nilab: おなかすいた ...

iPhone 4S + Echofon (アプリ)

Echofon Pro for Twitter version 5.1.5 を使用。

 coordinatesgeoplace
iPhone + Echofon (アプリ)××

{
  "in_reply_to_screen_name": null,
  "place": {
    "name": "Nagoya City Nishi Ward",
    "country_code": "JP",
    "attributes": {},
    "full_name": "Nagoya City Nishi Ward, Aichi",
    "url": "http://api.twitter.com/1/geo/id/6169466efdfafa79.json",
    "bounding_box": {
      "type": "Polygon",
      "coordinates": [
        [
          [
            136.855966666667,
            35.1709238888889
          ],
          [
            136.908068888889,
            35.1709238888889
          ],
          [
            136.908068888889,
            35.2345627777778
          ],
          [
            136.855966666667,
            35.2345627777778
          ]
        ]
      ]
    },
    "place_type": "city",
    "country": "Japan",
    "id": "6169466efdfafa79"
  },
  "favorited": false,
  "id_str": "183027206631596032",
  "geo": null,
  "user": {
    "id_str": "5704532",
    "id": 5704532
  },
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "retweet_count": 0,
  "retweeted": false,
  "truncated": false,
  "in_reply_to_user_id_str": null,
  "coordinates": null,
  "source": "<a href=\"http://www.echofon.com/\" rel=\"nofollow\">Echofon</a>",
  "created_at": "Fri Mar 23 03:07:41 +0000 2012",
  "contributors": null,
  "id": 183027206631596030,
  "in_reply_to_user_id": null,
  "text": "はらへ #harahe"
}

placeオブジェクトの経度緯度ポリゴンを地図上に展開するとこんな感じ。
iPhone + Echofon (アプリ)

iPhone 4S + Echofon Pro for Twitter version 5.1.5
Twitter / @nilab: はらへ #harahe ...

iPhone 4S + foursquare (アプリ)

 coordinatesgeoplace
iPhone + foursquare (アプリ)

{
  "in_reply_to_screen_name": null,
  "place": {
    "name": "Nagoya City Nishi Ward",
    "country_code": "JP",
    "attributes": {},
    "full_name": "Nagoya City Nishi Ward, Aichi",
    "url": "http://api.twitter.com/1/geo/id/6169466efdfafa79.json",
    "bounding_box": {
      "type": "Polygon",
      "coordinates": [
        [
          [
            136.855966666667,
            35.1709238888889
          ],
          [
            136.908068888889,
            35.1709238888889
          ],
          [
            136.908068888889,
            35.2345627777778
          ],
          [
            136.855966666667,
            35.2345627777778
          ]
        ]
      ]
    },
    "place_type": "city",
    "country": "Japan",
    "id": "6169466efdfafa79"
  },
  "favorited": false,
  "id_str": "183023361012678656",
  "possibly_sensitive": false,
  "geo": {
    "type": "Point",
    "coordinates": [
      35.17593059,
      136.88562512
    ]
  },
  "user": {
    "id_str": "5704532",
    "id": 5704532
  },
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "retweet_count": 0,
  "retweeted": false,
  "truncated": false,
  "in_reply_to_user_id_str": null,
  "coordinates": {
    "type": "Point",
    "coordinates": [
      136.88562512,
      35.17593059
    ]
  },
  "source": "<a href=\"http://foursquare.com\" rel=\"nofollow\">foursquare</a>",
  "created_at": "Fri Mar 23 02:52:24 +0000 2012",
  "contributors": null,
  "id": 183023361012678660,
  "in_reply_to_user_id": null,
  "text": "I'm at デイリーヤマザキ 名古屋Pセントラル店 (名古屋市, 愛知県) http://t.co/jbkHfEut"
}

placeオブジェクトの経度緯度ポリゴンとcoordinates/geoオブジェクトをアイコンとして地図上に展開するとこんな感じ。
iPhone 4S + foursquare (アプリ)

iPhone 4S + foursquare (アプリ)
Twitter / @nilab: I'm at デイリーヤマザキ 名古屋Pセントラル店 ...

iPhone 4S + nilogger (自作アプリ)

nilogger (自作 iPhone アプリ) ではツイートする際に lat, long パラメータを付加して投稿している。 place_id は付加していないが、投稿後に Twitter API で取得すると place オブジェクトも存在していた。

 coordinatesgeoplace
iPhone + nilogger (自作アプリ)

{
  "in_reply_to_screen_name": null,
  "place": {
    "name": "小牧市",
    "country_code": "JP",
    "attributes": {},
    "full_name": "小牧市, 愛知県",
    "url": "http://api.twitter.com/1/geo/id/393fdb830543dade.json",
    "bounding_box": {
      "type": "Polygon",
      "coordinates": [
        [
          [
            136.881159722222,
            35.2554238888889
          ],
          [
            137.045684722222,
            35.2554238888889
          ],
          [
            137.045684722222,
            35.3389138888889
          ],
          [
            136.881159722222,
            35.3389138888889
          ]
        ]
      ]
    },
    "place_type": "city",
    "country": "日本",
    "id": "393fdb830543dade"
  },
  "favorited": false,
  "id_str": "183436331651833856",
  "geo": {
    "type": "Point",
    "coordinates": [
      35.27991972,
      136.91789
    ]
  },
  "user": {
    "id_str": "5704532",
    "id": 5704532
  },
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "retweet_count": 0,
  "retweeted": false,
  "truncated": false,
  "in_reply_to_user_id_str": null,
  "coordinates": {
    "type": "Point",
    "coordinates": [
      136.91789,
      35.27991972
    ]
  },
  "source": "<a href=\"http://www.nilab.info/lab/nilogger/\" rel=\"nofollow\">nilogger</a>",
  "created_at": "Sat Mar 24 06:13:24 +0000 2012",
  "contributors": null,
  "id": 183436331651833860,
  "in_reply_to_user_id": null,
  "text": "てstφ(゚ω゚=) \nほっかほっか亭常普請店 \n住所: 愛知県小牧市郷中1丁目29 \nTEL: 0568-76-4147 \nL:35.279919722222,136.917890000000"
},

placeオブジェクトの経度緯度ポリゴンとcoordinates/geoオブジェクトをアイコンとして地図上に展開するとこんな感じ。
iPhone 4S + nilogger

iPhone 4S + nilogger
Twitter / @nilab: てstφ(゚ω゚=) ほっかほっか亭常普請店  住 ...

「from Komaki City」のところがリンクになっていて、直接 http://maps.google.com/maps?q=Komaki+City%2C+Aichi%2C+Japan にリンクされている。
iPhone 4S + nilogger

こちらは PC + twitter.com から投稿したときのように https://twitter.com/#!/places/ 経由でリダイレクトされるようにはなっていない。

参考資料

Ref.

その他

地図上にポリゴンやアイコンを表示するのには Features View を使用。

tags: twitter location

Posted by NI-Lab. (@nilab)