Php HTTP请求失败-谷歌地图地理编码/HostGator
在这方面的帮助将不胜感激。我有一个txt/xml物理地址列表,我通过Google Maps地理编码脚本传递这些地址,但遇到了一个问题,地址在coord_lat上吐出一个空值,我的MySQL数据库拒绝了这个问题。我收到的错误是HTTP请求失败,因此我认为问题在于Google Maps拒绝我的连接并返回空值,这会破坏我的脚本/数据库。有人知道如何修复此连接和/或向脚本中添加内容吗?我目前正在使用HostGator作为我的托管服务 警告:文件获取内容()[函数.文件获取内容]:无法打开流:HTTP请求失败!第297行的/includes/func.php中禁止使用HTTP/1.0 403 {“status”:“Failed”,“data”:“SQLSTATE[23000]:完整性约束冲突:1048列'coord_lat'不能为null”} ErrorSyntaxError:意外标记Php HTTP请求失败-谷歌地图地理编码/HostGator,php,mysql,http,null,request,Php,Mysql,Http,Null,Request,在这方面的帮助将不胜感激。我有一个txt/xml物理地址列表,我通过Google Maps地理编码脚本传递这些地址,但遇到了一个问题,地址在coord_lat上吐出一个空值,我的MySQL数据库拒绝了这个问题。我收到的错误是HTTP请求失败,因此我认为问题在于Google Maps拒绝我的连接并返回空值,这会破坏我的脚本/数据库。有人知道如何修复此连接和/或向脚本中添加内容吗?我目前正在使用HostGator作为我的托管服务 警告:文件获取内容()[函数.文件获取内容]:无法打开流:HTTP请求
function get_lat_long($address, $zipcode) {
if(strlen($zipcode) == 4){
$zipcode = '0' . $zipcode;
//echo $zipcode . "\n";
}
$apikey = "AIzaSyBmT9F_ixjLlW8oDiYVqgHqt1888";
$geourl = "http://maps.google.com/maps/geo?key=" . $apikey . "&output=xml&q=" . urlencode($address) . "+" . urlencode($zipcode);
//echo $geourl;
//echo "<br>";
// Grab XML content using $geourl
$context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$xml = file_get_contents($geourl, false, $context);
$xml = simplexml_load_string($xml);
//Parse the lat and long from the XML
$Lat = $xml->results->result->locations->location->displayLatLng->latLng->lat;
//echo $Lat;
$Lng = $xml->results->result->locations->location->displayLatLng->latLng->lng;
//echo $Lng;
//Return
if($Lng && $Lat) {
return array('lat'=>$Lat,
'lng'=>$Lng
);
} else {
return false;
}
函数get_lat_long($address,$zipcode){
if(strlen($zipcode)==4){
$zipcode='0'。$zipcode;
//echo$zipcode。“\n”;
}
$apikey=“AIzaSyBmT9F_ixjLlW8oDiYVqgHqt1888”;
$geourl=”http://maps.google.com/maps/geo?key=“$apikey.”&output=xml&q=“.urlencode($address)。“+”.urlencode($zipcode);
//echo$geourl;
//回声“”; //使用$geourl获取XML内容 $context=stream\u context\u create(数组('http'=>array('header'=>'Accept:application/xml')); $xml=file\u get\u contents($geourl,false,$context); $xml=simplexml\u load\u字符串($xml); //从XML解析lat和long $Lat=$xml->results->result->locations->location->displayLatLng->latLng->Lat; //echo$Lat; $Lng=$xml->results->result->location->location->displayLatLng->latLng->Lng; //echo$Lng; //返回 如果($Lng和$Lat){ 返回数组('lat'=>$lat, “液化天然气”=>液化天然气美元 ); }否则{ 返回false; }
}使用谷歌地图v3我想你现在使用的是v2,它不再工作了
$Address = urlencode($Address);
$url='http://maps.googleapis.com/maps/api/geocode/json?address=egypt&sensor=false';
$source = file_get_contents($url);
$obj = json_decode($source);
$lat = $obj->results[0]->geometry->location->lat;
$lng = $obj->results[0]->geometry->location->lng;
我相信你可能是对的。我注意到$url中包含埃及。如何添加我的urelencode
。urlencode($address)。"+" . urlencode($zipcode)
到这个url?试试这个:json?components=country:us | postal|u code:zipcode&sensor=false