Cake Php パン屋へ行こう
- 1. 第 5 回 SE 勉強会 2008/4/20 (日)
- 18. /app/controllers/components/geocoder_jp.php class GeocoderJpComponent extends Object { var $apiKey = ‘(google api key)’; function getLatLng($address) { $url = 'http://maps.google.co.jp/maps/geo?output=xml&key='.$this->apiKey.'&q='; $xmlurl = $url . urlencode($address); $contents = mb_convert_encoding(file_get_contents($xmlurl), 'UTF-8', 'SJIS'); $geocoder = simplexml_load_string($contents); $i = 0; $result = array(); foreach ($geocoder->Response->Placemark as $value) { $coords = $value->Point->coordinates; list($lat, $lng) = split(',', $coords); $result[$i]['lat'] = $lat; $result[$i]['lng'] = $lng; $result[$i]['address'] = (string)$value->AddressDetails->Country->AddressLine; $i += 1; } return $result; } } ※ スペースの都合で一部カットしてあります