2011-03-31 59 views
1

有人可以幫我解決這個問題嗎? 我需要知道從一個地址的php經度和緯度。代理prob!em使用php中的simplexml_load_file

我做:

$地址=用urlencode( '我的地址');

$ lat_lng = simplexml_load_file(「http://maps.google.com/maps/api/geocode/xml?address= {$ address} & sensor = false」);

,但我得到了這樣的警告:

消息:使用simplexml_load_file() [function.simplexml加載文件]: php_network_getaddresses:的getaddrinfo 失敗:在名稱 解決臨時出現故障

我想我需要配置代理,所以我改變了這種方式:

$ address = urlencode('my address');

$ ch = curl_init(「http://maps.google.com/maps/api/geocode/xml?address= {$ address} & sensor = false」);

curl_setopt($ ch, CURLOPT_RETURNTRANSFER,1);

curl_setopt($ ch,CURLOPT_PROXY, 'my_proxy);

curl_setopt($ ch,CURLOPT_PROXYPORT, 'my + port');

$ lat_lng = simplexml_load_string(curl_exec($ ch));

curl_close($ ch);

當我打電話給curl_exec時它似乎被阻止。

回答

1

首先嚐試使用不帶代理服務器的設置,這可能是代理配置中的錯誤。

function curl($url){ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_close ($ch); 
    return curl_exec($ch); 
} 

$address = urlencode($address); 
$data = curl("http://maps.google.com/maps/api/geocode/xml?address=$address&sensor=false"); 
$lat_lng = simplexml_load_string($data); 
0

檢查你的代碼

curl_close ($ch); 

應該是函數內的最後一行