Question

I have a problem with this function

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];   
}

works well, but if I put it into a cycle of addresses sometimes skip an address (totally random). If I start the cycle twice sometimes skips a result and sometimes another.. I believe it is caused by timeout. can I wait until this function is ready?

thanks in advice

Était-ce utile?

La solution

tried again with sleep(5) and seems ok. I Googled and found that you can make 20 queries per second. I added usleep(500000), and now it works perfectly

Thanks Alfasin!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top