Example #1
0
 private static function SingleCurlExec($requestList)
 {
     $responseList = array();
     foreach ($requestList as $key => $request) {
         SingleCurl::instance()->open();
         SingleCurl::instance()->send($request);
         $responseList[$key] = SingleCurl::instance()->exec();
         SingleCurl::instance()->close();
     }
     return $responseList;
 }
Example #2
0
 function geocode_from_latlng($lat, $lng)
 {
     //**********************************************************************
     //unify format
     $lat = number_format($lat, 6, '.', '');
     $lng = number_format($lng, 6, '.', '');
     //Check if address is in geocode table
     $latlng = $lat . '.' . $lng;
     $dotaz = "SELECT * FROM handol5_data.s_geocode WHERE latlng='{$latlng}' LIMIT 1";
     $result = @mysqli_query($dotaz);
     if (!$result) {
         die('Invalid query: ' . mysqli_error($dotaz) . '; error code: ' . mysqli_errno($dotaz));
     }
     $num_rows = mysqli_num_rows($result);
     if ($num_rows == 1) {
         while ($zaznam = mysqli_fetch_array($result)) {
             print_r($zaznam);
             return $zaznam;
         }
     } else {
         // single curl request
         $sc = new SingleCurl();
         $result = $sc->request("http://where.yahooapis.com/geocode?location=" . $lat . "," . $lng . "&gflags=R&appid=NhjeGJ72", 'x');
         //**********************************************************************
         echo "<br />";
         print_r($result['INF']);
         echo "<hr />";
         $patterns = array('error' => '//resultset/error', 'errormessage' => '//resultset/errormessage', 'found' => '//resultset/found', 'quality' => '//resultset/result/quality', 'latitude' => '//resultset/result/latitude', 'longitude' => '//resultset/result/longitude', 'line1' => '//resultset/result/line1', 'line2' => '//resultset/result/line2', 'line3' => '//resultset/result/line3', 'line4' => '//resultset/result/line4', 'house' => '//resultset/result/house', 'street' => '//resultset/result/street', 'postal' => '//resultset/result/postal', 'city' => '//resultset/result/city', 'country' => '//resultset/result/country');
         //get all relevent information from XML
         $address = new xpath();
         $address_array = $address->getVariousItems($result['EXE'], $patterns);
         //show error message if error
         if ($address_array['error'] == '1') {
             echo 'error yahoo geocoding - ' . $address_array['errormessage'];
         } else {
             //remove elements which won't be put into database
             unset($address_array['error']);
             unset($address_array['errormessage']);
             unset($address_array['found']);
             //create index value
             $latlng = $address_array['latitude'] . '.' . $address_array['longitude'];
             $address_array['latlng'] = $latlng;
             //write to database
             $query = new mysqli_queries();
             $query->insert('handol5_data.s_geocode', $address_array);
         }
         echo "<hr />";
         //**********************************************************************
         //Check if address is in geocode table
         $latlng = $lat . '.' . $lng;
         $dotaz = "SELECT * FROM handol5_data.s_geocode WHERE latlng='{$latlng}' LIMIT 1";
         $result = @mysqli_query($dotaz);
         if (!$result) {
             die('Invalid query: ' . mysqli_error($dotaz) . '; error code: ' . mysqli_errno($dotaz));
         }
         $num_rows = mysqli_num_rows($result);
         if ($num_rows == 1) {
             while ($zaznam = mysqli_fetch_array($result)) {
                 print_r($zaznam);
                 return $zaznam;
             }
         } else {
             echo "<span style='color:red;'>error - check geocode class, function geocode_from_latlng()</span><br />";
         }
     }
 }