facebook twitter hatena line google mixi email

Google/Googlemap/GeoCoding

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

緯度軽度取得api作成

  1. プロジェクトを作成(https://code.google.com/apis/console
  2. Google Maps Geocoding API を選択
  3. apiキーを作成し保存しておく

使い方

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=[apikey]

レスポンスデータサンプル

https://developers.google.com/maps/documentation/geocoding/intro?hl=ja

phpで取得

$url = "https://maps.googleapis.com/maps/api/geocode/json?address="
               .urlencode($this->_trimAddress(address))
               ."&key=".$api;
echo $url."\n";
$json = file_get_contents($url);
$gmap = json_decode($json,1);
if (array_key_exists('results', $gmap)
   && array_key_exists(0, $gmap['results'])
   && $gmap['results'][0]['geometry']['location']) {
        $lat = $gmap['results'][0]['geometry']['location']['lat'];
        $lng = $gmap['results'][0]['geometry']['location']['lng'];
}
echo $lat."\n";
echo $lng."\n";

回数制限

2,500リクエスト/日
5リクエスト/秒

参考:http://maplesystems.co.jp/blog/programming/20127.html