mixiアプリで位置情報の取り扱い
mixiアプリで位置情報の取り扱い
Mixiの位置情報サービスを使用して経度・緯度の座標を取得
↓
YahooAPIの逆ジオコーディングを使用して座標から住所に変換
↓
都道府県別の処理
という流れ。
1.下準備
日本郵便のサイトから全国の市町村データを取得しDBに格納
http://www.post.japanpost.jp/zipcode/dl/oogaki.html
2.mixiアプリのjavascriptを使用して経度と緯度を取得
資料 http://developer.mixi.co.jp/appli/spec/touch/using_userflow_api/geolocation_api
<script type="text/javascript"> function showMap(latitude, longitude) { // do_something } mixi.requestFetchGeolocation(function(response) { if (response.hadError()) { var errCode = response.getErrorCode(); alert(response.getErrorMessage()); } else { var geo = response.getData(); if (typeof(geo) != 'undefined') { geo.getCurrentPosition(function(position) { showMap(position.coords.latitude, position.coords.longitude); }); } else { alert("Your browser doesn't support geolocation."); } } }); </script>
3.YahooのAPIから逆ジオコーディング
資料 リバースジオコーダ
http://developer.yahoo.co.jp/webapi/map/openlocalplatform/v1/reversegeocoder.html
<?php define('ReverseGeoCoder','http://reverse.search.olp.yahooapis.jp/OpenLocalPlatform/V1/reverseGeoCoder'); define('YahooAppID','****************'); $url = ReverseGeoCoder.'?lat='.$lat."&lon=".$lon."&appid=".YahooAppID; $xml = simplexml_load_file($url); $prefecture_name = $xml->Feature->Property->AddressElement[0]->Name; $city_name = $xml->Feature->Property->AddressElement[1]->Name; ?>
今回は使用していないが
資料 ローカルサーチ
http://developer.yahoo.co.jp/webapi/map/localsearch/v1/localsearch.html
も使い方によっては面白そう!
4.
1.下準備で格納したDBに $prefecture_name と $city_nameで検索をかけて
アプリケーション側で面白いことをする!
その他.
ちなみに
逆ジオコーディングで
http://code.google.com/intl/ja/apis/maps/documentation/javascript/reference.html
http://code.google.com/intl/ja/apis/maps/documentation/javascript/reference.html
http://tsoftds.blog35.fc2.com/blog-entry-125.html
http://sites.google.com/site/gmapsapi3/Home/services
http://blueeyesblue.cocolog-nifty.com/technote/2009/01/google-api-1e7d.html
http://creco.net/2009/03/07/implement_google_reverse_geocoding_api/
を参照してgoogle Geocoding API v3なども試したけれど、
xmlが複雑でパースに苦労したので自分はyahoo APIを使用しました。