1
獲取經緯度我有一個問題,這個功能從谷歌
public function getCoords($address){
$coordinatesSplit=array(0=>0,1=>0);
$request_url = $this->_baseUrl . "&oe=utf-8&q=" . urlencode($address);
$xml = simplexml_load_file($request_url);
if (! empty($xml->Response)) {
$point= $xml->Response->Placemark->Point;
$coordinatesSplit = explode(",", $point->coordinates);
// Format: Longitude, Latitude, Altitude
}
$this->latitude = $coordinatesSplit[1];
$this->longitude= $coordinatesSplit[0];
}
效果很好,但如果我把它放到地址的週期有時會跳過一個地址(完全隨機)。 如果我開始循環兩次,有時會跳過結果,有時會跳過另一個結果。我認爲這是由超時引起的。 我可以等到這個功能準備好了嗎?
感謝的建議
當然。爲什麼不使用:http://php.net/manual/en/function.sleep.php? – alfasin
再次嘗試睡覺(5),似乎沒問題,謝謝你的評論。 我谷歌搜索,發現你可以每秒20個查詢。 我加了一個usleep(500000),現在它完美地工作 再次感謝 – Andreah
做得好!請將您評論的內容寫爲「答案」並接受它 - 以便其他人可以從中獲益。 :) – alfasin