function getlatlang($location,$region)
{
$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='. urlencode($location) .'&sensor=false$region='. urlencode($region));
$output= json_decode($geocode);
return $output->results[0]->geometry->location;
}
这是我在本地服务器上进行开发时一直使用的,现在我已经通过我的webhost使网站生效了,这不再返回位置。
不确定它有什么问题?
答案 0 :(得分:0)
function getlatlang($location,$region)
{
//$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='. urlencode($location) .'&sensor=false®ion='. urlencode($region));
$url = 'http://maps.google.com/maps/api/geocode/json?address='. urlencode($location) .'&sensor=false®ion='. urlencode($region);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$geocode = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
echo "\n<br />";
$contents = '';
} else {
curl_close($ch);
}
$output= json_decode($geocode);
return $output->results[0]->geometry->location;
}
我的网站主机不允许fopen,切换到curl()。