我想通过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;
?>
这非常适合从我的国家获得正确的数据,但不适用于其他人......
4 回答
您可以使用第二个api(由Thomas建议),如下所示:
试试这个..
编辑:::::
这是我解决问题的方法
您是否尝试过使用GeoCoding API?
https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding
示例:http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false
编辑:我在许多针对印度的应用程序中使用过它,它运行得很好 .