我有当前的纬度和经度,这个如何在php中获取区域名称或代码。请帮帮我。
答案 0 :(得分:1)
<?php
$geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng=48.283273,14.295041&sensor=false');
$output= json_decode($geocode);
echo $output->results[0]->formatted_address;
?>
这将获得完整的地址,因为您只需在该URL中传递lat long
答案 1 :(得分:0)
您可以使用geoplugin
。
尝试一次:
<?php
$geoPlugin_array = unserialize( file_get_contents('http://www.geoplugin.net/php.gp?ip=###.###.###.###') );//Replcae ###.###.###.### with your ip address.
echo '<pre>';
print_r($geoPlugin_array);
echo '</pre>';
?>
希望这可以帮助你。