我上传CSV文件,并在$地址变量中获得地址字段,但是当我通过$地址谷歌地图,它显示我的错误,谷歌地图未能打开流错误
file_get_contents(http://maps.googleapis.com/maps/api/geocode/json?address=9340+Middle+River+Street%A0%2COxford%2CMS%2C38655): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request.
我搜索它的解决方案,我发现一个只编码地址,但它也没有工作对我来说...
CODE
if (!empty($address)) {
$geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address));
$geo = json_decode($geo, true);
if ($geo['status'] = 'OK') {
if (!empty($geo['results'][0])) {
$latitude = $geo['results'][0]['geometry']['location']['lat'];
$longitude = $geo['results'][0]['geometry']['location']['lng'];
}
$mapdata['latitude'] = $latitude;
$mapdata['longitude'] = $longitude;
return $mapdata;
} else {
$mapdata['latitude'] = "";
$mapdata['longitude'] = "";
return $mapdata;
}
}
错误是在行
$geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address));
我错过了什么。 任何帮助是非常赞赏..谢谢