2016-05-21 1 views
1

Google APIを使用すると、緯度、緯度、経度を取得し、同じ特定の国を取得します。どうしたらいいですか? (PHPを使用)Google APIを使用する場所からの緯度、経度を取得し、特定の国を取得する(PHPを使用)

$formattedAddr = str_replace(' ','+',$address); 
//Sending request and receive json data by address 

$geocodeFromAddr=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.$formattedAddr.'&sensor=false'); 
$output = json_decode($geocodeFromAddr); 

//Get latitude and longitute from json data 

$data['latitude'] = $output->results[0]->geometry->location->lat; 
$data['longitude'] = $output->results[0]->geometry->location->lng; 

答えて

0

プロパティを取得します。formatted_addressから取得します。完全なアドレスが含まれており、カンマ区切りの後にで区切られています。お試しください:

$formatted_address = $output->results[0]->formatted_address; 

$country = trim(end(explode(',',$formatted_address))); 
関連する問題