「Google/Googlemap/GeoCoding」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→phpで取得) |
|||
行10: | 行10: | ||
==phpで取得== | ==phpで取得== | ||
− | + | $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); | |
− | + | $gmap = json_decode($json,1); | |
− | + | $lat = $gmap['results'][0]['geometry']['location']['lat']; | |
− | + | $lng = $gmap['results'][0]['geometry']['location']['lng']; | |
− | echo $lat."\n"; | + | echo $lat."\n"; |
− | echo $lng."\n"; | + | echo $lng."\n"; |
2016年8月4日 (木) 18:00時点における版
緯度軽度取得api作成
- プロジェクトを作成(https://code.google.com/apis/console
- Google Maps Geocoding API を選択
- 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); $lat = $gmap['results'][0]['geometry']['location']['lat']; $lng = $gmap['results'][0]['geometry']['location']['lng']; echo $lat."\n"; echo $lng."\n";