facebook twitter hatena line email

「Google/Googlemap/GeoCoding」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(phpで取得)
 
(同じ利用者による、間の4版が非表示)
行10: 行10:
  
 
==phpで取得==
 
==phpで取得==
            $url = "https://maps.googleapis.com/maps/api/geocode/json?address="
+
$url = "https://maps.googleapis.com/maps/api/geocode/json?address="
 
                 .urlencode($this->_trimAddress(address))
 
                 .urlencode($this->_trimAddress(address))
 
                 ."&key=".$api;
 
                 ."&key=".$api;
echo $url."\n";
+
echo $url."\n";
            $json = file_get_contents($url);
+
$json = file_get_contents($url);
            $gmap = json_decode($json,1);
+
$gmap = json_decode($json,1);
            $lat = $gmap['results'][0]['geometry']['location']['lat'];
+
if (array_key_exists('results', $gmap)
            $lng = $gmap['results'][0]['geometry']['location']['lng'];
+
    && array_key_exists(0, $gmap['results'])
echo $lat."\n";
+
    && $gmap['results'][0]['geometry']['location']) {
echo $lng."\n";
+
        $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

2017年7月25日 (火) 13:42時点における最新版

緯度軽度取得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