Blog Top > iPhone > | 地図 > Google Maps APIの逆ジオコードを使ってみる

Google Maps APIの逆ジオコードを使ってみる

  • Posted by: tagchan
  • 2008年12月 8日 00:19
  • iPhone | 地図

いつの間にか,Google Maps APIで逆ジオコードができるようになっていた。ジオコードは,住所から緯度経度を求めるが,逆ジオコードは,緯度経度から住所を求める。今まではジオコードは多かったが,逆ジオコードはあまりなかった。

今後,緯度経度(ジオタグ)が付与された写真やいろいろなデータが増加していくことが予想されるが,データの管理としては,やはり緯度経度の情報で扱われる可能性が高いだろう。それを,何かのサービスやアプリケーションで使う場合は,処理においては数字を使うことなるが,ユーザインターフェイスの観点からは人間の見た目で位置を瞬時に把握するために,住所として表現されることは非常に重要である。そういう意味で,気軽に逆ジオコードによって住所が取得できることの意義は大きいと思う。

さて,Google Maps APIで実際に逆ジオコードを行ってみる。RESTサービスで取得可能でありJSONでの出力に対応している。以下にサンプルを示す。

http://maps.google.com/maps/geo?oe=utf-8&ll=35.620519%2C139.438892&key=ABQIAAAANb5JuD4i3v_Isz_A_z4ipxTrwmVSgF6tOzG2piSiw3F-ORmacRQGqjoiQ55HzLvszowcXYUDT1mXwA&output=json&callback=gmap

コールバック関数はgmapとしている。結果は以下の通りである。

gmap && gmap({
  "name": "35.620519,139.438892",
  "Status": {
    "code": 200,
    "request": "geocode"
  },
  "Placemark": [ {
    "id": "p1",
    "address": "日本東京都多摩市貝取2丁目9−1",
    "AddressDetails": {"Country": {"CountryNameCode": "JP","CountryName": "日本","AdministrativeArea": {"AdministrativeAreaName": "東京都","Locality": {"LocalityName": "多摩市","DependentLocality": {"DependentLocalityName": "貝取","Thoroughfare":{"ThoroughfareName": "9−1 2丁目"}}}}},"Accuracy": 8},
    "Point": {
      "coordinates": [ 139.4391663, 35.6206892, 0 ]
    }
  }, {
    "id": "p2",
    "address": "日本東京都多摩市貝取2丁目9",
    "AddressDetails": {"Country": {"CountryNameCode": "JP","CountryName": "日本","AdministrativeArea": {"AdministrativeAreaName": "東京都","Locality": {"LocalityName": "多摩市","DependentLocality": {"DependentLocalityName": "貝取","Thoroughfare":{"ThoroughfareName": "9 2丁目"}}}}},"Accuracy": 7},
    "Point": {
      "coordinates": [ 139.4386358, 35.6205225, 0 ]
    }
  }, {
    "id": "p3",
    "address": "日本東京都多摩市貝取2丁目",
    "AddressDetails": {"Country": {"CountryNameCode": "JP","CountryName": "日本","AdministrativeArea": {"AdministrativeAreaName": "東京都","Locality": {"LocalityName": "多摩市","DependentLocality": {"DependentLocalityName": "貝取","Thoroughfare":{"ThoroughfareName": "2丁目"}}}}},"Accuracy": 4},
    "Point": {
      "coordinates": [ 139.4399301, 35.6219557, 0 ]
    }
  }, {
    "id": "p4",
    "address": "日本東京都多摩市貝取",
    "AddressDetails": {"Country": {"CountryNameCode": "JP","CountryName": "日本","AdministrativeArea": {"AdministrativeAreaName": "東京都","Locality": {"LocalityName": "多摩市","DependentLocality": {"DependentLocalityName": "貝取"}}}},"Accuracy": 4},
    "Point": {
      "coordinates": [ 139.4381358, 35.6235749, 0 ]
    }
  }, {
    "id": "p5",
    "address": "日本東京都多摩市",
    "AddressDetails": {"Country": {"CountryNameCode": "JP","CountryName": "日本","AdministrativeArea": {"AdministrativeAreaName": "東京都","Locality": {"LocalityName": "多摩市"}}},"Accuracy": 4},
    "Point": {
      "coordinates": [ 139.4463069, 35.6370041, 0 ]
    }
  }, {
    "id": "p6",
    "address": "日本東京",
    "AddressDetails": {"Country": {"CountryNameCode": "JP","CountryName": "日本","AddressLine":["東京"]},"Accuracy": 2},
    "Point": {
      "coordinates": [ 139.4872858, 35.6837135, 0 ]
    }
  }, {
    "id": "p7",
    "address": "日本東京都",
    "AddressDetails": {"Country": {"CountryNameCode": "JP","CountryName": "日本","AdministrativeArea": {"AdministrativeAreaName": "東京都"}},"Accuracy": 2},
    "Point": {
      "coordinates": [ 139.6917064, 35.6894875, 0 ]
    }
  }, {
    "id": "p8",
    "address": "日本Honshu",
    "AddressDetails": {"Country": {"CountryNameCode": "JP","CountryName": "日本","AddressLine":["Honshu"]},"Accuracy": 1},
    "Point": {
      "coordinates": [ 138.0803529, 36.0786279, 0 ]
    }
  }, {
    "id": "p9",
    "address": "日本",
    "AddressDetails": {"Country": {"CountryNameCode": "JP","CountryName": "日本"},"Accuracy": 1},
    "Point": {
      "coordinates": [ 138.2529240, 36.2048240, 0 ]
    }
  }, {
    "id": "p10",
    "address": "アジア",
    "AddressDetails": {"AddressLine":["アジア"],"Accuracy": 0},
    "Point": {
      "coordinates": [ 108.3307000, 34.3644390, 0 ]
    }
  } ]
}
)

この緯度経度に意味は無く適当に入れた数字である。Placemarkの配列が後になるほど,空間的にカバーする範囲が広くなる。しまいには,アジアなんていうのもあり,これはこれでおもしろい。

このAPIを活用することにした。先日,Brightkite APIで自分の位置を示すブログパーツを作成したが,これに応用してみる。Brightkiteでは,ある位置に「チェックインする」という概念を用いている。iPhoneのBrightkiteアプリでは,GPSを使って,その位置に気軽にチェックインできるのだ。しかし,国内では,日本語の住所が出てこない。そのため,例えば,下北沢の付近のある地点は「Yoyogi-sanyachō, , Japan」と表示され,大変分かりづらい。

そこで,APIで出力される緯度経度を用いて,上記の逆ジオコードAPIによって,代わりに日本語住所を表記させるようにしてみた。先日のエントリで示したbrightkite.jsは,既にこれに対応して書き換えられている。

Comments:0

Comment Form

Trackbacks:0

TrackBack URL for this entry
http://www.tagchan.net/cgi/mt-tb.cgi/202
Listed below are links to weblogs that reference
Google Maps APIの逆ジオコードを使ってみる from Tagchan's Blog

Blog Top > iPhone > | 地図 > Google Maps APIの逆ジオコードを使ってみる

Search
Recent Entries
人気エントリー
    Categories
    Photos
    Feeds
    なかのひと

    Return to page top