Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 谷歌地理编码器忽略搜索地址中的国家_Php_Geocoding - Fatal编程技术网

Php 谷歌地理编码器忽略搜索地址中的国家

Php 谷歌地理编码器忽略搜索地址中的国家,php,geocoding,Php,Geocoding,这就是问题所在:用户选择酒店名称、城市和国家,然后使用Google Places查找该位置,以便在Google地图中添加标记 城市和国家连接到一个名为$code(用逗号分隔)的变量中,该变量通过以下方式进行搜索: function getLatLong($code){ $code=str_replace(" ", "+", $code); $query = "http://maps.googleapis.com/maps/api/geocode/json?address=".$code."&am

这就是问题所在:用户选择酒店名称、城市和国家,然后使用Google Places查找该位置,以便在Google地图中添加标记

城市和国家连接到一个名为
$code
(用逗号分隔)的变量中,该变量通过以下方式进行搜索:

function getLatLong($code){
$code=str_replace(" ", "+", $code);
$query = "http://maps.googleapis.com/maps/api/geocode/json?address=".$code."&sensor=false";
$data = file_get_contents($query);
// if data returned
if($data){
    // convert into readable format
    $data = json_decode($data);
    $long = $data->results[0]->geometry->location->lat;
    $lat = $data->results[0]->geometry->location->lng;
    return array('Latitude'=>$lat,'Longitude'=>$long);
}
else{
    return false;
}
}
然后使用返回的lat/lng对将酒店名称搜索区域居中。然而,地理编码员似乎完全无视这个国家,因此如果
$code=“圣何塞,哥斯达黎加”
它只搜索“圣何塞”,然后返回加利福尼亚州圣何塞

这是一个巨大的问题,因为许多城市都有相同的名字,特别是在南美洲

因为这是一个全球范围的搜索,所以为每个国家创建坐标多边形是不可能的

有人能解决这个问题吗?

在示例中,将
中的“哥斯达黎加圣何塞”
放在
$code
中,查询URL返回来自哥斯达黎加圣何塞(和其他地方)的点击数。也许只是因为“哥斯达黎加”不是一个国家?