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で検索をかけて
アプリケーション側で面白いことをする!