GoogleMapsAPIに住所を渡すと各種情報をXML形式で返してくれるのを利用して、住所から緯度経度を配列で返す関数を作成
function get_gps_from_address( $address='' ){
$res = array();
$req = 'http://maps.google.com/maps/api/geocode/xml';
$req .= '?address='.urlencode($address);
$req .= '&sensor=false';
$xml = simplexml_load_file($req) or die('XML parsing error');
if ($xml->status == 'OK') {
$location = $xml->result->geometry->location;
$res['lat'] = (string)$location->lat[0];
$res['lng'] = (string)$location->lng[0];
}
return $res;
}
$latlng = get_gps_from_address('東京都');
print_r($latlng);
//実行結果
/*
Array
(
[lat] => 35.6894875
[lng] => 139.6917064
)
*/