我希望通过Google Maps API(V3?)获取经纬度所在的国家、地区和城市名称,并使用PHP进行翻译。但我无法为每个县获取到正确的结果,虽然我已经编写了以下代码,但其对于其他县不起作用,因为返回的结果不同(唯一正确的信息是国家,但即使是这个信息也是以本地语言而非英语返回的):
<?
$lok1 = $_REQUEST['lok1'];
$lok2 = $_REQUEST['lok2'];
$url = 'http://maps.google.com/maps/geo?q='.$lok2.','.$lok1.'&output=json';
$data = @file_get_contents($url);
$jsondata = json_decode($data,true);
if(is_array($jsondata )&& $jsondata ['Status']['code']==200)
{
$addr = $jsondata ['Placemark'][0]['AddressDetails']['Country']['CountryName'];
$addr2 = $jsondata ['Placemark'][0]['AddressDetails']['Country']['Locality']['LocalityName'];
$addr3 = $jsondata ['Placemark'][0]['AddressDetails']['Country']['Locality']['DependentLocality']['DependentLocalityName'];
}
echo "Country: " . $addr . " | Region: " . $addr2 . " | City: " . $addr3;
?>
这个方法可以很好地获取我国的正确数据,但对其他国家不适用...